Home > Backend Development > PHP Tutorial > Obtain data, simulate login, and POST data directly through curl_PHP tutorial

Obtain data, simulate login, and POST data directly through curl_PHP tutorial

WBOY
Release: 2016-07-13 10:28:53
Original
1012 people have browsed it

The Markdown editor in Blog Park is so cheating@! ! ! never mind. No more formatting! ! !

<code>/********************** curl 系列 ***********************/
//直接通过curl方式取得数据(包含POST、HEADER等)
/*
 * $url: 如果非数组,则为http;如是数组,则为https
 * $header: 头文件
 * $post: post方式提交 array形式
 * $cookies: 0默认无cookie,1为设置,2为获取
 */
public function curl_allinfo($urls, $header = FALSE, $post = FALSE, $cookies = 0) {
    $url = is_array($urls) ? $urls['0'] : $urls;
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

    //带header方式提交
    if($header != FALSE){
        curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    }

    //post提交方式
    if($post != FALSE){
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
    }

    if($cookies == 1){
        curl_setopt($ch, CURLOPT_COOKIEJAR, "cookiefile");
    }else if($cookies == 2){
        curl_setopt($ch, CURLOPT_COOKIEFILE, "cookiefile");
    }

    if(is_array($urls)){
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    }

    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
}
</code>
Copy after login

oupag bbs:http://www.oupag.com/bbs/thread-7814-1-1.html cnblogs:http://www.cnblogs.com/skiy/p/3766330.html

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/780025.htmlTechArticleThe Markdown editor in Blog Park is so cheating@! ! ! never mind. No more formatting! ! ! /************************** curl series ***********************///Get data directly through curl...
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