function GetIP()
{
if(getenv('HTTP_X_FORWARDED_FOR')) {
$ip = getenv('HTTP_X_FORWARDED_FOR');
}
else if(getenv('HTTP_CLIENT_IP')) {
$ip = getenv('HTTP_CLIENT_IP');
}
else {
$ip = getenv('REMOTE_ADDR');
}
return($ip);
}
function CountMe($base)
{
$basesql="regnierschmitnet";
$db_user="regnierschmitnet";
$db_pw="Ymiq-780";
$laps = 3600;
$now = time();
$agent = getenv('HTTP_USER_AGENT');
$ip = GetIP();
$db = mysql_connect("sql.regnier-schmit.net", $db_user, $db_pw);
if(!$db){
exit;
}
if(!mysql_select_db($basesql, $db)){
exit;
}
$result1 = mysql_query("SELECT * FROM userlist WHERE base='$base'");
while ($val = mysql_fetch_array($result1)) {
if(($val["last"] + $laps) < $now){
$thisTimeStamp = $val["last"];
$thisAgent = $val["agent"];
$thisIP = $val["ip"];
mysql_query("DELETE FROM userlist WHERE base='$base' AND last='$thisTimeStamp' AND agent='$thisAgent' AND ip='$thisIP'");
}
}
$result0 = mysql_query("SELECT * FROM userlist WHERE base='$base' AND agent='$agent' AND ip='$ip'");
$c = mysql_numrows($result0);
$count = 1;
$updateCount = 0;
if($c == 0){
$updateCount = 1;
mysql_query("INSERT INTO userlist(base, last, agent, ip) VALUES('$base', '$now', '$agent', '$ip')");
}
else {
mysql_query("UPDATE userlist SET last='$now' WHERE base='$base' AND agent='$agent' AND ip='$ip'");
}
$count = 1;
$result = mysql_query("SELECT * FROM counter WHERE base='$base'");
$c = mysql_numrows($result);
if($c == 0) {
mysql_query("INSERT INTO counter(base, number) VALUES('$base','1')");
}
else {
while ($val = mysql_fetch_array($result)) {
$thisCount=$val["number"];
if($updateCount) {
$thisCount++;
mysql_query("UPDATE counter SET number='$thisCount' WHERE base='$base'");
}
if($count < $thisCount){
$count = $thisCount;
}
}
}
mysql_close();
return($count);
}
?>
Astronomie