Jump to content

Referring Website trouble


Smudly

Recommended Posts

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

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

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');

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.