美文网首页
php curl模拟 浏览器 伪装客户端 访问 真实可用 银行卡

php curl模拟 浏览器 伪装客户端 访问 真实可用 银行卡

作者: geeooooz | 来源:发表于2019-11-29 17:05 被阅读0次

转载:https://blog.csdn.net/qq_22385935/article/details/101532588

public function getUrlContent()
    {

        $origin = 'http://www.lianhanghao.com'; //目标网址
        $referer = $origin . "/cardbin.html";//当前页面
        $apiUrl = $origin . "/admin/api/getBankdata";//请求的api地址
        $data = ['cardno' => ''];//此处填写的是银行卡或者信用卡的卡号
        
        //注意了,这里的hear信息比较关键, 请先用ajax测试访问成功,然后把请求信息复制过来替换
        $header = [
            'Accept: application/json, text/javascript, */*; q=0.01',
//            'Accept-Encoding: gzip, deflate, br',
            'Accept-Language: zh-CN,zh;q=0.9',
            'Connection: keep-alive',
            'Content-Type: application/x-www-form-urlencoded; charset=UTF-8',
//            'Cookie: PHPSESSID=340abf1a618653fef13589101044e994; ZDEDebuggerPresent=php,phtml,php3; CNZZDATA1583751=cnzz_eid%3D572091052-1569547668-%26ntime%3D1569553068',
//            'Host: localhost_mlf.com',
            'Origin: ' . $origin,
            'Referer:' . $referer,
            'User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36',
            'X-Requested-With: XMLHttpRequest',
        ];
        // 初始化一个curl会话
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $apiUrl);
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_POST, 1); //设置为POST方式
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); //数据传输
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); //解决重定向问题

        // 执行一个curl会话
        $contents = curl_exec($ch);
        // 返回一个保护当前会话最近一次错误的字符串
        $error = curl_error($ch);
        if ($error) {
            echo 'Error: ' . $error;
        }
        // 关闭一个curl会话
        curl_close($ch);
        return $contents;
    }

————————————————
版权声明:本文为CSDN博主「洋葱 ☠」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_22385935/article/details/101532588

相关文章

网友评论

      本文标题:php curl模拟 浏览器 伪装客户端 访问 真实可用 银行卡

      本文链接:https://www.haomeiwen.com/subject/hspgwctx.html