Hello.
The task is to save the referrer to cookies. I use this code:
<? if( isset( $_SERVER['HTTP_REFERER']) && (!$_COOKIE['last_ref'])) { SetCookie( 'last_ref', $_SERVER['HTTP_REFERER']); } ?>
If during the life of a session you arrive at the target page from different sources, then the very first source is saved in the cookie and is not overwritten every time (which is necessary).
The problem is that the cookie is overwritten every time you wander through the site’s own pages (the top code is shown on each page), despite the condition for the existence of a cookie named " last_ref
". If, however, prohibit memorizing the referrer, which coincides with its own site, then the cookie is generally empty.
What is wrong in the code?