Get original URL referer with PHP?

Keith Donegan picture Keith Donegan · Dec 8, 2009 · Viewed 309k times · Source

I am using $_SERVER['HTTP_REFERER']; to get the referer Url. It works as expected until the user clicks another page and the referer changes to the last page.

How do I store the original referring Url?

Answer

Sampson picture Sampson · Dec 8, 2009

Store it either in a cookie (if it's acceptable for your situation), or in a session variable.

session_start();

if ( !isset( $_SESSION["origURL"] ) )
    $_SESSION["origURL"] = $_SERVER["HTTP_REFERER"];