| px | top | add code | search | signup | login | help |
refer.php3
<?
/*
Refer Copyright 2000 Brian Ross
Version 1.0
brian@music4free.com
AIM: DeadBrain3
ICQ: 15273600
http://brian.zero-gravity.org/php/
How to install:
1. Edit the variables below to fit your needs.
2. Create the datafile that you showed in $referfile and chomd to it 777.
3. Use either a PHP or SSI include to insert the script onto the page you want it to track.
*/
$referfile = "/usr/home/brian/public_html/php-bin/refer.dat"; // Path to refer.dat file
$clickadmin = "http://brian.zero-gravity.org/php-bin/referadmin.php3"; // URL to referadmin.php3
/*
if (!empty ($url)){echo "$url";}
else {echo "Referer Was Not Set!!";}
Unmark this if you want the script to print the referrer.
*/
$url = "$HTTP_REFERER";
if (file_exists($referfile))
{
$temparray = file($referfile);
for($index = 0; $index < count($temparray); $index++)
{
$entry = explode("|",$temparray[$index]);
if(!strcmp($entry[1],$url))
{
$entry[0]++;
$tempentry = $entry;
$temparray[$index] = implode($entry,"|");
$fp = fopen($referfile,"w");
if(flock($fp,2))
{
for($index = 0; $index < count($temparray); $index++)
fputs($fp,$temparray[$index]);
}
else
exit("Refer error: flock write failure!");
if(flock($fp,3))
fclose($fp);
else
exit("Refer error: flock release failure!");
$written = TRUE;
}
}
if($written == FALSE)
{
$hits = "1";
$entry = "$hits|$url|$since\n";
$fp = fopen($referfile,"a");
if(flock($fp,2))
fputs($fp,$entry,256);
else
exit("Refer error: flock write failure!");
if(flock($fp,3))
fclose($fp);
else
exit("Refer error: flock release failure!");
}
}
else
{
exit("Refer error: $referfile missing!");
}
?>
referadmin.php3
<?
$referfile = "/usr/home/brian/public_html/php-bin/refer.dat"; // path to refer.dat file
$password = "loser"; //password to access admin
$fontf = "Verdana, Arial, Helvetica, Lucida, sans-serif"; //fonts
$fonts = "-1"; //font size
$trcolorh = "#D3D3D3"; //main table color
function usecolor()
{
$trcolor1 = "#EEEEEE";
$trcolor2 = "$trcolor1";
static $colorvalue;
if($colorvalue == $trcolor1)
$colorvalue = $trcolor2;
else
$colorvalue = $trcolor1;
return($colorvalue);
}
// check password
if($pass != $password)
{
echo "<html><head><title>Refer Admin - Enter Password</title></head><body>";
echo "<form method=\"post\" action=$PHP_SELF>";
echo "Enter your password:<br>";
echo "<input type=\"password\" name=\"pass\">";
echo "<input type=\"submit\" value=\"continue\">";
echo "</form></body></html>";
}
else
{
echo "<html><head><title>Refer Admin</title></head>";
echo "<body bgcolor=\"#FFFFFF\" text=\"#000000\" link=\"#0000FF\" vlink=\"#0000FF\" alink=\"#FF0000\">";
echo "<table width=\"100%\" border=\"0\">";
echo "<tr bgcolor=\"$trcolorh\"><td><font face=\"$fontf\" size=\"$fonts\"><b>Page</b></font></td>";
echo "<td><font face=\"$fontf\" size=\"$fonts\"><b>Hits</b></font></td>";
echo "<td><font face=\"$fontf\" size=\"$fonts\"><b>Since</b></font></td></tr>";
if (file_exists($referfile))
{
$temparray = file($referfile);
for($index = 0; $index < count($temparray); $index++)
{
$entry = explode("|",$temparray[$index]);
$trcolor = usecolor();
echo "<tr bgcolor=\"$trcolor\"><td><font face=\"$fontf\" size=\"$fonts\"><a href=\"$entry[1]\">$entry[1]</a></font></td>";
echo "<td><font face=\"$fontf\" size=\"$fonts\">$entry[0]</font></td>";
echo "<td><font face=\"$fontf\" size=\"$fonts\">$entry[2]</font></td></tr>";
}
}
else
{
echo "<tr><td>Refer Admin error: $referfile missing!</td></tr>";
}
echo "</table>";
echo "</body></html>";
}
?>
Comments or questions?
PX is running PHP 5.2.11
Thanks to Miranda Productions for hosting and bandwidth.
Use of any code from PX is at your own risk.