Posted by: The_webmaster Feb 8 2021, 05:02 AM
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
Posted by: 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?
Posted by: The_webmaster Feb 8 2021, 10:57 AM
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
Posted by: pandy Feb 8 2021, 11:45 AM
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.
Posted by: 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.
Posted by: The_webmaster Feb 8 2021, 12:31 PM
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
Posted by: pandy Feb 8 2021, 01:20 PM
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.
Posted by: The_webmaster Feb 8 2021, 02:08 PM
Thanks for your reply, i just converted the php code to javascript and it worked perfectly.