Suppose my site's url is given as hyperlink on some page on the internet; that page could be anything on internet - blog, orkut, yahoo, even stackoverflow etc, and someone clicks on it,and visited my site. So can we know, using php, the previous url from which the visitor came to my page?
6 Answers
Use the $_SERVER['HTTP_REFERER']
header, but bear in mind anybody can spoof it at anytime regardless of whether they clicked on a link.

- 700,868
- 160
- 1,392
- 1,356
-
1Is it cross browser solution? – Smile Mar 20 '14 at 10:45
-
1@NullPointer: Like I said in my answer, anybody can spoof it, so I guess the answer to your question is no. – BoltClock Mar 20 '14 at 10:46
-
1No. I wanted to ask in different way. – Smile Mar 20 '14 at 10:48
-
6I meant it that does it supported by all browsers? – Smile May 14 '14 at 11:28
-
@NullPointer yes it does, it supports all modern browsers. – Jan 01 '21 at 12:12
I can't add a comment yet, so I wanted to share that HTTP_REFERER is not always sent.

- 1
- 1

- 207
- 3
- 12
But you could make an own link for every from url.
Example: http://example.com?auth=holasite
In this example your site is: example.com
If somebody open that link it's give you the holasite value for the auth variable.
Then just $_GET['auth'] and you have the variable. But you should have a database to store it, and to authorize.
Like: $holasite = http://holasite.com (You could use mysql too..)
And just match it, and you have the url.
This method is a little bit more complicated, but it works. This method is good for a referral system authentication. But where is the site name, you should write an id, and works with that id.

- 191
- 1
- 13

- 21
- 2
Basically we are using the $_SERVER['HTTP_REFERER'] for getting the previous url for our site but it is waste of time it gives you the half url. So, the best way to get previous URL is Javascript and Jquery.

- 27
- 5
-
Please share more details. How **exactly** would you do that? Also, what do you mean by "half url"? – Nico Haase Feb 04 '22 at 10:48