Curl related issues

Source: Internet
Author: User
Curl problem
What do the following code not get the right cookie?

$url = "http://www.edai365.cn/Index/login.aspx";
$useragent = "mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; TheWorld) ";
$cookie = "Cnzz_eid=43361819-1349499907-&ntime=1349499907&cnzz_a=1&retime=1349499930944&sin=none &ltime=1349499930944&rtime=0 ";
$ch = Curl_init ();
curl_setopt ($ch, Curlopt_url, $url);
curl_setopt ($ch, Curlopt_cookie, $cookie);
curl_setopt ($ch, Curlopt_referer, "http://www.edai365.cn/Index/login.aspx");
curl_setopt ($ch, Curlopt_header, false);
curl_setopt ($ch, Curlopt_returntransfer, 1);
curl_setopt ($ch, curlopt_useragent, $useragent);
Curl_exec ($ch);
$tempCn = Curl_multi_getcontent ($ch);
Curl_close ($ch);
echo $tempCn;


------Solution--------------------
$cookie _jar= "";
curl_setopt ($ch, Curlopt_cookiejar, $cookie _jar);
Specify the save address of a cookie;
When you use it.
Plus curl_setopt ($ch 2, Curlopt_cookiefile, $cookie _jar);

Do not know the character does not meet your requirements
------Solution--------------------
I don't know what you're doing.
Http://www.edai365.cn/Index/login.aspx is the landing page, the core is a form
If you want to simulate landing, at least you need to simulate the submitted form data
------Solution--------------------
I tested, can crawl to the successful login information, as to why enter the landing page I did not study understand.
PHP Code
Analog Request data function request ($url, $postfields, $referer = ', $cookie _jar= './cookie.txt ') {$Cur = Curl_init (); $Opt = Array (Curlopt_url = $url, Curlopt_header = 1, curlopt_nobody = 1, Curlopt_        Port = 80,//ports Curlopt_post = 1,//Send a regular POST request, type: application/x-www-form-urlencoded, just like the form submitted.  Curlopt_postfields = $postfields,//All data to be transmitted, if a file is to be transmitted, [email protected] Curlopt_returntransfer =        The information obtained by 1,//is returned in the form of a file stream, rather than as a direct output.        Curlopt_ssl_verifyhost = 1,//Check that the SSL encryption algorithm exists from the certificate Curlopt_ssl_verifypeer = 0,//checks for the source of the certificate, and 0 indicates that the validation of the certificate is blocked. Curlopt_cookie = Getcook ($url), curlopt_useragent = "mozilla/4.0 (compatible; MSIE 6.0;        Windows NT 5.0) ",//a string that simulates a user's use of a browser that contains a" user-agent "header in an HTTP request. Curlopt_useragent = ' mozilla/5.0 (Windows NT 6.1; WOW64; rv:9.0.1) gecko/20100101 firefox/9.0.1 ', curlopt_followlocation = 0, Curlopt_cookiejar = Dirname (__f Ile__). $cookie _jar, curlopt_cookiefile = Dirname (__file__). $cookie _jar, curlopt_referer = $referer,)    ;    Curl_setopt_array ($Cur, $Opt);    $code = curl_exec ($Cur);    Curl_close ($Cur);    Unset ($Cur); Return $code;}    Function Getcook ($url) {$Curl =curl_init ($url);    curl_setopt ($Curl, curlopt_header,1);    curl_setopt ($Curl, curlopt_returntransfer,1);    $Cook =curl_exec ($Curl);    Curl_close ($Curl);    $Out = "; Preg_match ("/_sessionid\= (. [ ^;]    *)/I ", $Cook, $Out); Return $Out [1];} $url = "Http://www.edai365.cn/Index/login.aspx"; $postfields = ' txt_nickname=baluwu&txt_pwd=000000& Ddlcookietime= '. UrlEncode (' one week '). ' &ibt_login= '; $a =request ($url, $postfields); unset ($postfields, $url); Echo "<textarea style="width:100%;height:200px">", Chr (Ten), $a, Chr (Ten),"</textarea>";D ie ();
------Solution--------------------
Http://www.21andy.com/blog/20080507/1095.html
Look, maybe it's helpful.
------Solution--------------------
The best way to solve this problem is to intercept the packet and see what the difference is between the normal package and the curl communication package.
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.