zoukankan      html  css  js  c++  java
  • curl模拟登录

     1 <?php
     2 $post_data = array("username"=>"yuejide@163.com","password"=>"yuejide198225","remember"=>0); 
     3 $data = http_build_query($post_data); 
     4 $ch = curl_init(); 
     5 curl_setopt($ch, CURLOPT_URL, "http://www.imooc.com/user/login"); 
     6 curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);//不要直接输出 
     7 
     8 date_default_timezone_set('PRC'); 
     9 curl_setopt($ch, CURLOPT_COOKIESESSION,1); 
    10 curl_setopt($ch, CURLOPT_COOKIEFILE,"cookiefile"); 
    11 curl_setopt($ch, CURLOPT_COOKIEJAR,"cookiefile"); 
    12 curl_setopt($ch, CURLOPT_COOKIE,session_name().'='.session_id()); 
    13 curl_setopt($ch, CURLOPT_HEADER,0); 
    14 //这样设置能够让curl支持页面跳转 
    15 curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1); 
    16 curl_setopt($ch, CURLOPT_POST,1); 
    17 curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 
    18 curl_setopt($ch, CURLOPT_HTTPHEADER,array("application/x-www-form-urlencoded;charset=utf8","Content-length:".strlen($data))); 
    19 curl_exec($ch);//执行 
    20 curl_setopt($ch, CURLOPT_URL, "http://www.imooc.com/space/index"); 
    21 curl_setopt($ch, CURLOPT_POST,0); 
    22 curl_setopt($ch, CURLOPT_HTTPHEADER,array("Content-type:text/html")); 
    23 $output = curl_exec($ch); 
    24 curl_close($ch); 
    25 //打印数据 
    26 echo $output;
  • 相关阅读:
    Vue日期转化
    javascript数组去重
    javascript数组及类数组详解
    javascript的argument和克隆方法详解
    javascript中对this的理解
    javascript命名空间及对象枚举的理解
    javascript继承模式详解
    javascript的call和apply区别
    javascript原型及原型链详解
    javascript对象及包装类
  • 原文地址:https://www.cnblogs.com/gide/p/4439951.html
Copyright © 2011-2022 走看看