Help - Search - Members - Calendar
Full Version: how to detect a redirected url
HTMLHelp Forums > Programming > Server-side Scripting
The_webmaster
Please guys i want a code which i can use to detect the url that redirected to my webpage. Both php and javascript is accepted
Christian J
Do you mean the URL of any other website? Then you can detect the "referer" HTTP header with either javascript or PHP. It's possible for users to change it though, so don't rely on it for security.

Or do you mean one of your own pages redirecting to another?
The_webmaster
QUOTE(Christian J @ Feb 8 2021, 08:44 AM) *

Do you mean the URL of any other website? Then you can detect the "referer" HTTP header with either javascript or PHP. It's possible for users to change it though, so don't rely on it for security.

Or do you mean one of your own pages redirecting to another?

Yes url from another website
pandy
So you mean a simple link to your site from some other site?

In addition to what Christian said the referer header should be in your access logs and a statistics software that read the logs will display the URLs of referring pages.
Christian J
With PHP you can use

CODE
echo $_SERVER['HTTP_REFERER'];

See also https://www.php.net/manual/en/reserved.variables.server.php

Note that there will not always be a referer value, e.g. if the user followed a bookmark or typed the URL in the browser's address bar.
The_webmaster
QUOTE(Christian J @ Feb 8 2021, 12:07 PM) *

With PHP you can use

CODE
echo $_SERVER['HTTP_REFERER'];

See also https://www.php.net/manual/en/reserved.variables.server.php

Note that there will not always be a referer value, e.g. if the user followed a bookmark or typed the URL in the browser's address bar.

Thank you very much rolleyes.gif
pandy
QUOTE(Christian J @ Feb 8 2021, 06:07 PM) *

Note that there will not always be a referer value, e.g. if the user followed a bookmark or typed the URL in the browser's address bar.


Or the browser doesn't provide that information.
The_webmaster
Thanks for your reply, i just converted the php code to javascript and it worked perfectly.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2024 Invision Power Services, Inc.