Hi, I am trying to get it so that when a user signs up on my site it shows in a field in the db the page that refered them. So I have used this code: <?php session_start(); $_SESSION['referer'] = $_SERVER['HTTP_REFERER'] ; ?> PHP: The thing is, I need it to catch referers on every page in case they enter the site on register.php instead of index.php but the issue I have is if somebody goes from index.php to register.php the http_referer then becomes index.php so is pointless. How can I get it so that when people fill in the form on register.php, it shows how they came to the site in the first place? Thanks
If you just want to check how they accessed register.php, (and make sure the referer is not your own site). Simply add the following @ register.php: <?php $domain1 = str_replace("www.", "", $_SERVER['HTTP_HOST']); $domain2 = str_replace("www.", "", parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST)); if(!$domain1 == $domain2){ $referer = $_SERVER['HTTP_REFERER']; } else { //if referer is your site or their is no refer $referer = "None"; } ?> PHP: Then use the variable $referer wherever you want to place/include it.
Thanks for that, I will try it I managed to do it this way, does it look ok? <?php session_start(); if(isset($_SESSION['views'])) $_SESSION['views']=$_SESSION['views']+1; else { $_SESSION['views']=1; } if ($_SESSION['views']=="1") { $_SESSION['referer'] = $_SERVER['HTTP_REFERER'] ; } else { } ?> PHP:
I recommend you sanitize the $_SERVER['HTTP_REFERER'], I am guessing you are going to save that somewhere, probably a MySQL DB. ex: mysql_real_escape_string($_SERVER['HTTP_REFERER']);