Hi,
Got a bit of a problem. The tracking code below, tracks each click with the following URL http://www.mydomain.com/bannertrak/phptrak.php?http://www.myotherdomain.com
However instead of using the URL after php? I want to use say abcde & then have the php convert this to the URL.
I'm not exactly hip with PHP any help would be appreciated.
The problem is that one of my friends has a banner on their site & we want to track the hits out. Problem is his php driven site, is reading the tracking code as 2 seperate URL's
Any ideas?
Thanks TrezzAU 🙂
$CHECK_URL = FALSE;
$CHECK_URL_REGEX = "/^(http:|ftp:\/\/).*(\.+).*/i";
$CHECK_REFERER = FALSE;
$REFERER_SUBSTRING = "xxxxxxxxx.com";
$LOG_FILE_PATH = "/www/sites/xxxx/www.xxxxxx.com/bannertrak/trak/index.html";
//-------------------------------------
$QS = $_SERVER["QUERY_STRING"];
//now check if $QS looks like a URL
if($CHECK_URL && !preg_match($CHECK_URL_REGEX, $QS)){
//this didn't match
echo "<p>The URL direction does not seem to point to a valid URL.</p>";
exit;
}
if($CHECK_REFERER){
if (!stristr($_SERVER["HTTP_REFERER"], $REFERER_SUBSTRING)){
echo "<p>The referer does not match. Please make sure that the link you clicked came from the right site.</p>";
exit;
}
}
//If we have made it throught the checks, we write to the log file.
if($fd = @fopen($LOG_FILE_PATH, "r+")) {
//lock access for reading
flock($fd, 1);
//get the entire file contents
while(!feof($fd)) {
$data .= fgets($fd, 8000);
}
if(preg_match("|<tr><td class=\"DataTD\"><a href=\"$QS\">$QS<\/a><\/td><td class=\"DataTD\">(.*)<\/td><\/tr>\n|", $data, $matches)){
//we are already tracking this one
$count = $matches[1];
$count++;
$CountReplacementStr = "<tr><td class=\"DataTD\"><a href=\"$QS\">$QS</a></td><td class=\"DataTD\">" . $count . "</td></tr>\n";
$data = preg_replace("|<tr><td class=\"DataTD\"><a href=\"$QS\">$QS</a></td><td class=\"DataTD\">.*</td></tr>\n|", $CountReplacementStr , $data);
}
else{
$data = preg_replace("|<!--INSERT_NEW_LOGS_HERE-->|", "<!--INSERT_NEW_LOGS_HERE-->\n<tr><td class=\"DataTD\"><a href=\"$QS\">$QS</a></td><td class=\"DataTD\">1</td></tr>\n", $data);
}
flock($fd, 3);//release the lock
fclose($fd);
$fd = @fopen($LOG_FILE_PATH, "w+");
flock($fd, 2);//lock for writing.
fputs($fd, $data);
fflush($fd);
flock($fd, 3);//release lock.
fclose($fd);
//echo "QS is " . $QS;
header("Location: " . $QS);
}