返回在线用户卷曲

时间:2015-09-19 07:08:52

标签: php curl

使用此代码只能在localhost上返回在线用户。当发送到webhost崩溃时,甚至在第二次调用中寻找令牌代码示例。它仅适用于在网站页面源代码上生成的第二个参数tokem。如何从webhost运行此脚本?

if (!function_exists('getHistats')) {
    function getHistats($sid = 0, $cc = '') {

        if (empty($sid) || empty($cc))
            return 'error';

        $url    = 'http://www.histats.com/viewstats/HST_GET_SUMMARY.php';
        $result = '';

        $ualist = array(
            'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.2; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)',
            'Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.23 (KHTML, like Gecko) Ubuntu/10.04 Chromium/11.0.688.0 Chrome/11.0.688.0 Safari/534.23',
            'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.14) Gecko/20110221 Ubuntu/10.04 (lucid) Firefox/3.6.14 GTB7.1',
            'Opera/9.80 (X11; Linux i686; U; en) Presto/2.7.62 Version/11.01',
            'Midori/0.2.2 (X11; Linux i686; U; en-us) WebKit/531.2+',
            'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20100101 Firefox/15.0',
            'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1150.1 Iron/20.0.1150.1 Safari/536.11'
        );

        if (function_exists('curl_init')) {

            $http_headers                 = array();
            $http_headers[]               = 'Host: www.histats.com';
            $http_headers[]               = 'Referer: www.histats.com/viewstats/?sid='. $sid .'&act=2&f=1';
            $http_headers[]               = 'X-Requested-With: XMLHttpRequest';

            $opts                         = array();
            $opts[CURLOPT_URL]            = $url;
            $opts[CURLOPT_HTTPHEADER]     = $http_headers;
            $opts[CURLOPT_CONNECTTIMEOUT] = 5;
            $opts[CURLOPT_TIMEOUT]        = 10;
            $opts[CURLOPT_USERAGENT]      = $ualist[rand(0, count($ualist) - 1)];
            $opts[CURLOPT_HEADER]         = FALSE;
            $opts[CURLOPT_RETURNTRANSFER] = TRUE;
            $opts[CURLOPT_POST]           = 1;
            $opts[CURLOPT_POSTFIELDS]     = 'AR_REQ[sid]='. $sid .'&AR_REQ[CC]='. $cc .'&dbg=1';

            # Initialize PHP/CURL handle
            $ch = curl_init();
            curl_setopt_array($ch, $opts);
            # Create return array
            $result = curl_exec($ch);

            curl_close($ch);

        } elseif (ini_get('allow_url_fopen')) {
            $result = file_get_contents($url);
        }


        if (empty($result) || ($result == 'error=11') || ($result == 'err:1'))
            return 'error';

        $obj = json_decode($result);

        return isset($obj->livearray->livesummary->cur_online) ? $obj->livearray->livesummary->cur_online : 0;
    }
}

$html = file_get_contents('http://histats.com/viewstats/?sid=3041076&act=2&f=1');

preg_match("/OBJ_summary.sockTOKEN = '(.*?)'/i", $html, $match);

echo 'Online: '. getHistats('3041076', 'bjh1NStBTVZyMFJzRENTODFHTHNQamJyV0FvY2l4TGRNSk5FczQyYnR3dERlaUhWczJZNUtWQk5lU2p6STlyRTZCQXZUd2t6MWJzS3Z2cWs2d1g4aXc9PQ==');
echo '<br />';
echo 'Token: '. $match[1];
echo '<br />';
echo 'Online: '. getHistats('3041076', $match[1]);

0 个答案:

没有答案