Re: Page name for form submit: REQUEST_URI or SCRIPT_NAME
| From: | Daniel Brown | Date: | Sat, 27 Dec 2008 17:52:07 +0000 |
| Subject: | Re: Page name for form submit: REQUEST_URI or SCRIPT_NAME | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-285099@lists.php.net to get a copy of this message | ||
On Sat, Dec 27, 2008 at 12:31, Dotan Cohen <dotancohen@gmail.com> wrote:
> Is there a compelling reason to use either REQUEST_URI or SCRIPT_NAME
> in the action of a form that I want to submit to the same URL that it
> came from (the script parses whether or not there is a Submit to know
> if it should display the form or the results). I need a portable
> solution, that is why I am not hardcoding it. Also, the users _may_
> save the form to their hard drives, so simply leaving the action blank
> will not do.
>
> I know that REQUEST_URI includes the ?variable=value string and that
> SCRIPT_NAME does not. This form does not depend upon get variables, so
> this should never be an issue, but I ask here anyway to know if there
> are other differences that I did not account for.
Happy Chanukah, Dotan!
For portability's sake, especially if you anticipate users saving
the form to their local systems, I would recommend:
<?php
$action = "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
?>
<form method="<?php echo $action; ?>">
If you use REQUEST_URI and the form is on a page not called
directly (for example, on index.php and called only by directory; a
mod_rewrite /contact page; etc.), using REQUEST_URI gives the actual
request, where PHP_SELF gives the actual file.
--
</Daniel P. Brown>
daniel.brown@parasane.net || danbrown@php.net
http://www.parasane.net/ || http://www.pilotpig.net/
Unadvertised dedicated server deals, too low to print - email me to find out!