CURL

private function _login($type)
    {
        if($type == 'login')
        {
            $url = strstr($_SERVER['HTTP_HOST'], '51zxtx.com') ? "http://aa.com/session?type=0":"http://bb.com/session?type=0";
        }
        else
        {
            $url = strstr($_SERVER['HTTP_HOST'], '51zxtx.com') ? "http://aa.com/chatrooms":"http://bb.com/chatrooms";
        }
        $dat = array(
            'account' => '15986605737',
            'password' => '1234567',
        );
        $cookie_path = FCPATH.'application/cache/cookie/';
        mkdirs($cookie_path);
        $cookie_path .= $dat['account'].'.log';
        $data=json_encode($dat);
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type:application/json","I24-Ver:v1.1"));
        //---post--带上
//        curl_setopt($ch, CURLOPT_POST, true);
//        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        //---post--带上
        if($type == 'login')
        {
            curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_path);
        }
        else
        {
            curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_path);
        }
        curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
        $response = curl_exec($ch);
        pt($response);
        exit();
    }

你可能感兴趣的:(PHP,curl)