رتبه موضوع:
  • 0 رای - 0 میانگین
  • 1
  • 2
  • 3
  • 4
  • 5
یافتن تعداد افرادی که به سایت شما متصل شدن
#1
بدست اوردن IP کاربر :
1
2
3
4
5
6
7
8
function getIP() {
    $ip="";
    if (getenv("HTTP_CLIENT_IP")) $ip = getenv("HTTP_CLIENT_IP");
        else if(getenv("HTTP_X_FORWARDED_FOR")) $ip = getenv("HTTP_X_FORWARDED_FOR");
        else if(getenv("REMOTE_ADDR")) $ip = getenv("REMOTE_ADDR");
        else $ip = "";
    return $ip;
}

ذخیره سازی IP وشمارش :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
function howManyIps() {
    $filename = "./howmanyip.log";
    $seconds = 300;
    $yourIP = getIP();
 
    if (file_exists($filename.".lock")) $readonly = true; else $readonly=false;
 
    $count = 0;
    //lock the file
    if (!$readonly) $fpLock = fopen($filename.".lock", "w");
 
    //read data ips
    $fp = @fopen($filename, "r");
    $arIPS=explode ("n", @fread($fp,filesize($filename)) );
    @fclose($fp);
 
    //if file is locked get out
    if ($readonly) return count($arIPS);
 
    $s = "";
    $already=false;
    //update data and search user ip
    for ($i=0;$i<count($arIPS);$i++) {
 
        $arData= explode (" ", $arIPS[$i]);
 
        //update your user timer
        if ($yourIP==$arData[0]) {
            $already=true;
            $arData[1]=time();
        }
 
        // check if user is old
        if ( time()- (integer)$arData[1] < $seconds ){
            $s.=$arData[0]." ".$arData[1]."n";
            $count++;
        }
 
    }
 
    if (!$already) {
        //your user is new, add it to the list
        $s.=$yourIP." ".time()."n";
        $count++;
    }
 
    //save the list
    $fp = fopen($filename, "w");
    fwrite($fp,$s);
    fclose($fp);
 
    //remove thr lock
    fclose($fpLock);
    unlink($filename.".lock");
 
    return $count;
}

در هر صفحه ای که میخواین از سایت شمارش صورت بگیره تابع howManyIps رو فراخوانی کنید
پاسخ
تشکر شده توسط: php , abdollah110110




کاربران در حال بازدید این موضوع: 1 مهمان