Referring Website trouble

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Smudly
Forum Commoner
Posts: 71
Joined: Wed Jun 09, 2010 10:09 pm

Referring Website trouble

Post 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
Phoenixheart
Forum Contributor
Posts: 123
Joined: Tue Nov 16, 2004 7:46 am
Contact:

Re: Referring Website trouble

Post by Phoenixheart »

Did you check for mysql_error() ? Try var_dump() the variables before querying.
Smudly
Forum Commoner
Posts: 71
Joined: Wed Jun 09, 2010 10:09 pm

Re: Referring Website trouble

Post by Smudly »

tried for an error, and nothing came back. when using var_dump, for some reason it works on everything EXCEPT referrer.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Referring Website trouble

Post by AbraCadaver »

What is $url? 8)

Code: Select all

$referrerfinal = parse_url($url, PHP_URL_HOST);
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Smudly
Forum Commoner
Posts: 71
Joined: Wed Jun 09, 2010 10:09 pm

Re: Referring Website trouble

Post by Smudly »

That was actually a typo.
Where it says $url, it actually should be $referrer.
Post Reply