Page 1 of 1

Referring Website trouble

Posted: Sun Jun 13, 2010 7:12 pm
by Smudly
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?

Code: Select all

<?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:

Code: Select all

countid  	int(11)   	No   	    	 
date 	datetime 	No  	0000-00-00 00:00:00  	 
ip 	varchar(20) 	No  	  	 
referrer 	varchar(255) 	No 
Thanks

Re: Referring Website trouble

Posted: Mon Jun 14, 2010 6:03 am
by Phoenixheart
Did you check for mysql_error() ? Try var_dump() the variables before querying.

Re: Referring Website trouble

Posted: Tue Jun 15, 2010 10:55 am
by Smudly
tried for an error, and nothing came back. when using var_dump, for some reason it works on everything EXCEPT referrer.

Re: Referring Website trouble

Posted: Tue Jun 15, 2010 12:35 pm
by AbraCadaver
What is $url? 8)

Code: Select all

$referrerfinal = parse_url($url, PHP_URL_HOST);

Re: Referring Website trouble

Posted: Tue Jun 15, 2010 12:44 pm
by Smudly
That was actually a typo.
Where it says $url, it actually should be $referrer.