*RESOLVED* Help with Tracking script

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
User avatar
will83
Forum Commoner
Posts: 53
Joined: Thu Nov 10, 2005 3:13 pm

*RESOLVED* Help with Tracking script

Post by will83 »

Hi there, as above I have tried to implement a tracking script to log the referring URL (if any) into a database.

The problem: The script seems to be firing recordId() no matter whether it finds the domain name in the referring URL

Code: Select all

if(!$_SESSION['referrer'] && $_SERVER["HTTP_REFERER"]) { 
    $_SESSION['referrer'] = $_SERVER["HTTP_REFERER"]; 
    $referrer = $_SESSION['referrer']; 
    $string = "domain-name"; 
    if (strpos($referrer, $string) === FALSE) { 
        recordId(); 
    } 
} 

function recordId() { 
    global $conn; 
    $_SESSION['referrer'] = $_SERVER["HTTP_REFERER"]; 
    $_SESSION['sessionid'] = session_id(); 
    $sql = "INSERT into sessions VALUES ('', '".$_SESSION['referrer']."', '".$_SESSION['sessionid']."')"; 
    mysql_query($sql, $conn) or die("There was an error: <br />".mysql_error()); 
}

Any help/advice appreciated as always.
Last edited by will83 on Mon Mar 19, 2007 7:06 am, edited 1 time in total.
mentor
Forum Contributor
Posts: 100
Joined: Sun Mar 11, 2007 11:10 am
Location: Pakistan

Post by mentor »

try this

Code: Select all

if (strpos($referrer, $string) !== FALSE) { 
	recordId(); 
}
User avatar
will83
Forum Commoner
Posts: 53
Joined: Thu Nov 10, 2005 3:13 pm

Post by will83 »

Hi thanks for reply, resolved now.
Post Reply