Smudly Posted June 14, 2010 Share Posted June 14, 2010 I am trying to capture the website's name that links to my website. When a person clicks that link, it should add it to my database. For some reason though, it isn't working. Any suggestions?  <?php include('inc/connect.php'); $today = date("Y-m-d"); $ip = $_SERVER['REMOTE_ADDR']; $referrer = getenv('HTTP_REFERER'); $referrerfinal = parse_url($url, PHP_URL_HOST); echo $referrerfinal; $check = mysql_query("SELECT * FROM uniquevisitors WHERE ip='$ip'"); $unique = mysql_num_rows($check); if ($unique==0) {  $insert = mysql_query("INSERT INTO uniquevisitors VALUES ('',now(),'$ip','$referrerfinal')"); } else {  exit(); } ?>  Database:  countid int(11) No   date datetime No 0000-00-00 00:00:00 ip varchar(20) No  referrer varchar(255) No  Thanks Link to comment https://forums.phpfreaks.com/topic/204684-referring-website-trouble/ Share on other sites More sharing options...
teriyakichild Posted June 19, 2010 Share Posted June 19, 2010 The issue is that you are using the wrong variable name. Â Replace the following line: Â $referrerfinal = parse_url($url, PHP_URL_HOST); Â With: Â $referrerfinal = parse_url($referrer, PHP_URL_HOST); Â That will fix the issue. Â ------------------------------------------------------------------------------------------------------------------------------------ Tony Link to comment https://forums.phpfreaks.com/topic/204684-referring-website-trouble/#findComment-1074412 Share on other sites More sharing options...
Smudly Posted June 19, 2010 Author Share Posted June 19, 2010 Actually, I already caught that after I posted and fixed it. However, it still isn't capturing the website nor storing it in the database. Link to comment https://forums.phpfreaks.com/topic/204684-referring-website-trouble/#findComment-1074428 Share on other sites More sharing options...
teriyakichild Posted June 19, 2010 Share Posted June 19, 2010 The issue is in your query string (SELECT * FROM uniquevisitors WHERE ip='$ip'). You need to specify a date and time. You need to decided how long has to go by for a visit to be unique.  The way you have it now, once an ip is entered into the database, that visitor will never be entered in again. If you wanted to wait an hour for a visit to be unique then try it this way:  SELECT * FROM uniquevisitors WHERE ip='$ip' AND date > SUBTIME(NOW(),'0 01:00:00'); Link to comment https://forums.phpfreaks.com/topic/204684-referring-website-trouble/#findComment-1074430 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.