PHP SELF

Regelmatig wordt in formulieren de action als volgt ingesteld

1
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">

Op deze manier zorg je dat het formulier naar dezelfde pagina wordt verstuurd. Deze methode heeft echter als nadeel dat bij verkeerde instellingen je site gevoelig zal zijn voor XSS http://www.scriptorama.nl/security/tips-veiligere-site-phpself. Daarnaast is het niet nodig: Wanneer de action-attribute wordt weg- of leeggelaten, wordt het formulier al automatisch naar dezelfde pagina verstuurd.

Dit heeft dus hetzelfde effect:

1
<form action="" method="post">

Zie ook de specificaties van een URI reference http://www.ietf.org/rfc/rfc2396.txt:

4.2. Same-document References
 A URI reference that does not contain a URI is a reference to the
 current document.  In other words, an empty URI reference within a
 document is interpreted as a reference to the start of that document,
 and a reference containing only a fragment identifier is a reference
 to the identified fragment of that document.  Traversal of such a
 reference should not result in an additional retrieval action.
 However, if the URI reference occurs in a context that is always
 intended to result in a new request, as in the case of HTML's FORM
 element, then an empty URI reference represents the base URI of the
 current document and should be replaced by that URI when transformed
 into a request.

Bij een invalide URI is het gedrag niet gedefineerd http://www.w3.org/TR/REC-html40/interact/forms.html#adef-action, maar een lege URI is een valide relatieve URI.

Overkoepelende artikelen:
Inloggen wachtwoord vergeten? Aanmelden