In the header.php
file of my WordPress site I have the following code:
<?php
session_start();
$_SESSION['refererurl'] = $_SERVER['HTTP_REFERER'];
?>
To test the above code, I placed the following code in the front-page.php
file (and it works):
<?php
echo $_SESSION['refererurl'];
?>
I want to track the referrer URL that led a visitor to my site from an external site for tracking purposes. The problem is that $_SERVER['HTTP_REFERER']
resets on page-load, so while the information is useful when a visitor first lands on my website, it's overwritten whenever the visitor navigates further into my site.
Is there any way to store the value of $_SERVER['HTTP_REFERER']
when a visitor first arrives at my site from an external site for as long as the visitor is on my site?