Reputation: 943
I am redirecting from several pages to dev.php using php header
<?php header(Location: dev.php); ?>
I want to know from where i have been redirected here.
I have tried
<?php
print "You entered using a link on ".$_SERVER["HTTP_REFERER"];
?>
but it dosent work as $_SERVER["HTTP_REFERER"];
only works if you access dev.php using <a href="dev.php">Go to Developer Page</a>
So how can i get the referring URL?
Upvotes: 0
Views: 283
Reputation: 1275
The referer header is rather unreliable, there are antivirus software and firewalls out there that filter it completely. The only thing you can pretty safely rely on are cookies and with them, sessions.
Cookies are stored on the client side, in the browser, therefore can be manipulated, but if you are storing non-critical information, they can be enough.
Sessions nowadays rely on cookies as a means of starting them. A randomly generated hash is stored in a cookie, the corresponding data is stored on the server linked to this hash. When the client requests the next page, this data is retrieved. For more information about sessions read the corresponding section of the PHP manual.
As I wrote, sessions rely on cookies nowadays and you shouldn't do that unless you are aware of the security implications. You can however use URL parameters to pass the session ID along.
On a side note: in order to use cookies (and with them sessions) both the setting and the final URL must be on the same domain. If this isn't the case, you can use request parameters to pass the information along.
Upvotes: 0
Reputation: 1
You need to add the referer
to the header manually:
header("Referer: http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); // current page
header("Location: dev.php");
You can also do it using CURL. Have a look at an example function for that here: PHP - Referer redirect script
Upvotes: 0
Reputation: 6013
$_SERVER["HTTP_REFERER"] = 'YOUR_URL';
header('Location: dev.php');
exit(0);
Upvotes: 0
Reputation: 45134
Try something like below.
<?php header(Location: dev.php?referrer=$_SERVER[PHP_SELF]); ?>
header('Referer: '.$_SERVER['PHP_SELF']);
header(Location: dev.php);
If above methods don't work, You will have to go with sessions.
Upvotes: 2
Reputation: 442
You can pass the variable in GET:
<?php header('Location: dev.php?backurl='.$_SERVER[PHP_SELF]); ?>
And then take it in this way:
$backurl=$_GET['backurl'];
Upvotes: 1