php 獲得使用ip的問題?

edited 六月 2014 in PHP新手區
最近在寫一個網咖領取虛寶的機制

關於ip

有辦法獲得 使用者的 虛擬ip嗎

電腦名稱

每一台電腦不一樣的識別

因為網咖每一台電腦的對外ip都是一樣的

評論

  • http://stackoverflow.com/questions/4594823

    基本上透過代理伺服器連線可以從 HTTP_X_FORWARDED_FOR 取得進一步的 IP 資訊,但其實這個資訊相對的沒有參考價值,因為無從驗證。
  • edited 六月 2014
    HTTP_X_FORWARDED_FOR
    這參數我也曾在國外論壇程式裡發現過
    不過不管是實測還是翻PHP原始程式碼都沒發現就是
    不知是怎麼回事這樣

    若是需要自己補上PHP程式碼就算了 XD
    寧可錯殺一百也不可放過一人
    此時剛好適用
  • 這裡有比較完整的介紹:
    http://devco.re/blog/2014/06/19/client-ip-detection/
    <?php
    if(!empty($_SERVER['HTTP_CLIENT_IP'])){
       $myip = $_SERVER['HTTP_CLIENT_IP'];
    }else if(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
       $myip = $_SERVER['HTTP_X_FORWARDED_FOR'];
    }else{
       $myip= $_SERVER['REMOTE_ADDR'];
    }
    echo $myip;
    
  • php-5.5.13/sapi/litespeed/lsapilib.c

    看來屬於可以偽造的部份,可以選擇誠實或不誠實。
    static const char *CGI_HEADERS[H_TRANSFER_ENCODING+1] =
    {
        "HTTP_ACCEPT", "HTTP_ACCEPT_CHARSET",
        "HTTP_ACCEPT_ENCODING",
        "HTTP_ACCEPT_LANGUAGE", "HTTP_AUTHORIZATION",
        "HTTP_CONNECTION", "CONTENT_TYPE",
        "CONTENT_LENGTH", "HTTP_COOKIE", "HTTP_COOKIE2",
        "HTTP_HOST", "HTTP_PRAGMA",
        "HTTP_REFERER", "HTTP_USER_AGENT",
        "HTTP_CACHE_CONTROL",
        "HTTP_IF_MODIFIED_SINCE", "HTTP_IF_MATCH",
        "HTTP_IF_NONE_MATCH",
        "HTTP_IF_RANGE",
        "HTTP_IF_UNMODIFIED_SINCE",
        "HTTP_KEEP_ALIVE",
        "HTTP_RANGE",
        "HTTP_X_FORWARDED_FOR",
        "HTTP_VIA",
        "HTTP_TRANSFER_ENCODING"
    };
    
    static const char *HTTP_HEADERS[H_TRANSFER_ENCODING+1] = {
        "Accept", "Accept-Charset",
        "Accept-Encoding",
        "Accept-Language", "Authorization",
        "Connection", "Content-Type",
        "Content-Length", "Cookie", "Cookie2",
        "Host", "Pragma",
        "Referer", "User-Agent",
        "Cache-Control",
        "If-Modified-Since", "If-Match",
        "If-None-Match",
        "If-Range",
        "If-Unmodified-Since",
        "Keep-Alive",
        "Range",
        "X-Forwarded-For",
        "Via",
        "Transfer-Encoding"
    };
    
Sign In or Register to comment.