Просмотр файла includes/referal.php

Размер файла: 2.7Kb
<?php
$referal=addslashes(stripslashes(trim($_SERVER['QUERY_STRING'])));

$y2k = mktime(23,59,59,date('n'),date('j'),date('Y'));
setcookie('ref-'.$referal, 1, $y2k);
$vizit=$HTTP_COOKIE_VARS['ref-'.$referal];

$hua="*".strtoupper($_SERVER['HTTP_USER_AGENT']);

$browser=$_SERVER['HTTP_USER_AGENT'];

$komp=false;

$komp=(trim($hua)=='*')
||strpos($hua,'MOZILLA')
||strpos($hua,'MSIE')
||strpos($hua,'WINDOWS')
||strpos($hua,'KLONDIKE')
#||strpos($hua,'OPERA')
||strpos($hua,'M3GATE')
||strpos($hua,'EMULATOR')
||strpos($hua,'TAGTAG')
||strpos($hua,'ALPHACELL')
||strpos($hua,'WAPSILON')
||strpos($hua,'EZOS')
||strpos($hua,'BILBO')
||strpos($hua,'WINWAP')
||strpos($hua,'MYSOCK')
||strpos($hua,'BERCUT')
||strpos($hua,'WAPPER')
||strpos($hua,'TTPCOM')
||strpos($hua,'UNKNOWN')
||strpos($hua,'PORTALMMM')
||strpos($hua,'EZZE')
||strpos($hua,'JAVA')
||strpos($hua,'JBROWSER')
||strpos($hua,'SEND')
||strpos($hua,'WINSIM')
||strpos($hua,'WAPALIZER')
||strpos($hua,'TELEPORT')
||strpos($hua,'TSM')
||strpos($hua,'TCL')
||strpos($hua,'OPWV')
||strpos($hua,'SKT');
if ($komp) $browser='-komp-';

touch($rootpath.'/sluzhebnye/referal.dat');
if ($f=@fopen($rootpath.'/sluzhebnye/referal.dat',"r+"))
    {
    flock($f,2);
    # Проверка уникальности
    $unical=true;
    $data_unical='';
    $timestamp=time();
    $userinfo=trim(substr(substr($_SERVER['REMOTE_ADDR'].str_repeat(' ',15),0,15).' '.$browser,0,68));
    fseek($f,0,SEEK_SET);
    while (!feof($f))
        {
        $_timestamp=fread($f,10);
        $_userinfo=trim(fread($f,70));
        if ($timestamp-$_timestamp>3600) continue;
        $data_unical.=$_timestamp.' '.substr($_userinfo.str_repeat(' ',70),0,68)."\n";
        if ((substr($userinfo,0,15)==substr($_userinfo,0,15))&&(substr($_userinfo,15,6)=='-komp-')) $unical=false;
        if ($userinfo==$_userinfo) $unical=false;
        if ($vizit==1) $unical=false;
        }
    if ($unical) $data_unical.=$timestamp.' '.substr($userinfo.str_repeat(' ',70),0,68)."\n";
    fseek($f,0,SEEK_SET); fwrite($f,$data_unical);
    fclose($f);
    }

$q=@mysql(DBName,"SELECT * FROM `referal` WHERE `referal` = '$referal' AND `month` = '".date('m')."' AND `day` = '".date('d')."' AND `hour` = '".date('H')."' LIMIT 0, 1");
$s=@mysql_num_rows($q);
if ($s>0)
    {
    if ($unical) @mysql(DBName,"UPDATE `referal` SET `counter` = `counter` + 1 WHERE `referal` = '$referal' AND `month` = '".date('m')."' AND `day` = '".date('d')."' AND `hour` = '".date('H')."' LIMIT 1");
    }
else
    {
    @mysql(DBName,"INSERT INTO `referal` ( `referal` , `month` , `day` , `hour` , `counter` ) VALUES ( '$referal' , '".date('m')."', '".date('d')."', '".date('H')."' , '1' )");
    }

?>