note 68541 deleted from function.parse-url by bjori
| From: | bjori@php.net | Date: | Wed, 02 Aug 2006 12:53:02 +0000 |
| Subject: | note 68541 deleted from function.parse-url by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-115451@lists.php.net to get a copy of this message | ||
Note Submitter: kangaroo232002 at yahoo dot co dot uk
Reason: bad code
----
For a login function on a separate page, it's useful to send the user back to the page where
they came from (rather than just the home page or something) so the following function checks to see
if the file actually exists on the system (and is a valid referrer). It would be better to put the
referrer value into a hidden form on the page and then after post (and checking password etc) check
for $_POST['referrer'].
<?php
function referrer() {
$location = "location:index.php";
if (isset($_SERVER['HTTP_REFERER'])) {
$referrer = parse_url($_SERVER['HTTP_REFERER']);
$path = $referrer['path'];
$query = $referrer['query'];
$hardfile = str_replace($_SERVER['PHP_SELF'], "", __FILE__ . $path);
if(is_file($hardfile)) {
$location = "location:$path?$query";
}
}
header($location);
}
?>