How to get the previous url using PHP

PhpHttpUrlReferrer

Php Problem Overview


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?

Php Solutions


Solution 1 - Php

Use the $_SERVER['HTTP_REFERER'] header, but bear in mind anybody can spoof it at anytime regardless of whether they clicked on a link.

Solution 2 - Php

$_SERVER['HTTP_REFERER'] is the answer

Solution 3 - Php

$_SERVER['HTTP_REFERER'] will give you incomplete url.

If you want http://bawse.3owl.com/jayz__magna_carta_holy_grail.php, $_SERVER['HTTP_REFERER'] will give you http://bawse.3owl.com/ only.

Solution 4 - Php

I can't add a comment yet, so I wanted to share that HTTP_REFERER is not always sent.

https://stackoverflow.com/questions/19976189/notice-undefined-index-http-referer

Solution 5 - Php

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.

Solution 6 - Php

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionNawazView Question on Stackoverflow
Solution 1 - PhpBoltClockView Answer on Stackoverflow
Solution 2 - PhpAndreycoView Answer on Stackoverflow
Solution 3 - PhpTenTen PeterView Answer on Stackoverflow
Solution 4 - PhpNick DuBoisView Answer on Stackoverflow
Solution 5 - PhpKristóf BellaView Answer on Stackoverflow
Solution 6 - PhpSohang TyagiView Answer on Stackoverflow