php curl sends fake request

不言
Release: 2023-03-24 17:28:01
Original
2303 people have browsed it

This article mainly introduces php curl to send fake requests. Now I share it with you and give you a reference. Let’s follow the editor to take a look

    public function curlHtml(){
        //防止超时
        set_time_limit(0);        //要请求的网站的相关参数
        $url = "http://www.w3school.com.cn";        /*$data = array(
            'id'=>1
        );*/
        //初始化一个cURL会话
        $ch = curl_init();        //----------------------------------------

        //伪造来源地址,如果不设置,论坛服务器有可能有验证不允许回复 
        curl_setopt($ch,CURLOPT_REFERER,"http://www.w3school.com.cn");        //能保存cookie
        curl_setopt($ch,CURLOPT_COOKIESESSION,true);  
         //伪造用户浏览器
        curl_setopt($ch,CURLOPT_USERAGENT,"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36");        //伪造请求IP,可以为要请求的网站ip
        curl_setopt($ch, CURLOPT_PROXY, 'https://120.55.40.41:80');      
        //CURLOPT_RETURNTRANSFER 为true,它就将使用PHP curl获取页面内容或提交数据,作为变量储存,而不是直接输出。
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);    

        //------------------------------------------

        //使用post方式请求
        /*curl_setopt($ch, CURLOPT_POST, 1);
        //用来支持cookie
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);*/

        //--------------------------------------------

        //设置要请求的url
        curl_setopt($ch, CURLOPT_URL,$url);        //执行请求并获取放回数据  
        $res = curl_exec($ch);        return $res;


    }
Copy after login

Related recommendations:

Detailed analysis and common pitfalls of php curl using CURL in PHP

php CURL Get cookies simulated login method code example


#

The above is the detailed content of php curl sends fake request. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template