Page 1 of 1

*RESOLVED* Help with Tracking script

Posted: Mon Mar 19, 2007 4:59 am
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.

Posted: Mon Mar 19, 2007 6:29 am
by mentor
try this

Code: Select all

if (strpos($referrer, $string) !== FALSE) { 
	recordId(); 
}

Posted: Mon Mar 19, 2007 7:09 am
by will83
Hi thanks for reply, resolved now.