The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> how to detect a redirected url
The_webmaster
post Feb 8 2021, 05:02 AM
Post #1


Member
***

Group: Members
Posts: 40
Joined: 5-February 21
Member No.: 27,773



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

This post has been edited by The_webmaster: Feb 8 2021, 05:04 AM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Feb 8 2021, 08:44 AM
Post #2


.
********

Group: WDG Moderators
Posts: 9,630
Joined: 10-August 06
Member No.: 7



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?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
The_webmaster
post Feb 8 2021, 10:57 AM
Post #3


Member
***

Group: Members
Posts: 40
Joined: 5-February 21
Member No.: 27,773



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
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Feb 8 2021, 11:45 AM
Post #4


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,716
Joined: 9-August 06
Member No.: 6



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.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Feb 8 2021, 12:07 PM
Post #5


.
********

Group: WDG Moderators
Posts: 9,630
Joined: 10-August 06
Member No.: 7



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.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
The_webmaster
post Feb 8 2021, 12:31 PM
Post #6


Member
***

Group: Members
Posts: 40
Joined: 5-February 21
Member No.: 27,773



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
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Feb 8 2021, 01:20 PM
Post #7


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,716
Joined: 9-August 06
Member No.: 6



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.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
The_webmaster
post Feb 8 2021, 02:08 PM
Post #8


Member
***

Group: Members
Posts: 40
Joined: 5-February 21
Member No.: 27,773



Thanks for your reply, i just converted the php code to javascript and it worked perfectly.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 29th March 2024 - 12:35 AM