note 59350 deleted from reserved.variables by mazzanet
| From: | mazzanet@php.net | Date: | Sun, 25 Dec 2005 23:34:51 +0000 |
| Subject: | note 59350 deleted from reserved.variables by mazzanet | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-100701@lists.php.net to get a copy of this message | ||
Note Submitter: bnab at southplattewebdesign dot com
----
Earlier this was posted:
------------------
To display the url of a page (like the one in the address bar)
you can use this script:
<?php
echo "http://";
echo $_SERVER['HTTP_HOST']; //outputs sitename.com etc
echo $_SERVER['REQUEST_URI']; //outputs /index.php etc
?>
This could be used in a login script to redirect the user back to the page they logged in from
instead of the index
------------------
In reality to use this to redirect back, you have to send this information along with the posted
information as a hidden variable, in which case you could also referrence the
$_SERVER['PHP_SELF'] as the action of the login form (provided the handling code was in
the same file or included/required in the same file) and it will carry out the login function and
stay on the same page.
The comment of using it as a redirect is misleading, as $_SERVER['REQUEST_URI'] will, when
used on the login page, only show /login.php, not /index.php or /whereyoucamefrom.php. Which is
okay, if you have a login form on each page and not a dedicated login page to handle this procedure.
In my case, you could be on pageone.php and click the login link which takes you to login.php, then
the value of the variable is /login.php not the page you were on as the value is of the current
page, not the referring page.