In the web page crawled by CURL, other pages are referenced through the relative path. how does one solve the cookie problem? -Php Tutorial

Source: Internet
Author: User
In the web page crawled by CURL, other pages are referenced through the relative path. how does one solve the cookie problem? Curl relative path cookie

For example, if you use curl to capture page A, page A References page B through the relative path, Page B has the Set-Cookie header, and page A does not have Set-Cooike.
I can only capture page A through curl, but cannot catch the cookie because the cookie is set on page B. Ask experts to solve the problem! Thank you!


Reply to discussion (solution)

Captured twice/multiple times
In fact, ajax/verification code and so on are all done in this way.

Header ("Content-type: text/html; charset = utf-8"); function request_by_curl ($ remote_server, $ post_string) {$ ch = curl_init (); curl_setopt ($ ch, CURLOPT_URL, $ remote_server); curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ post_string); curl_setopt ($ ch, success, true); curl_setopt ($ ch, CURLOPT_NOBODY, false ); curl_setopt ($ ch, CURLOPT_HEADER, true); curl_setopt ($ ch, CURLOPT_HTTPHEADER, array (); $ data = curl_exec ($ ch); curl_close ($ ch ); return $ data;} // Obtain the verification code file_get_contents ("http://jysx.scnu.edu.cn/VerifyImg.aspx"); $ cookie = $ http_response_header [6]; $ code = substr ($ cookie, 23,4); echo $ code."
"; // Post login $ remote_server =" http://jysx.scnu.edu.cn/login.aspx "; $ post_string = 'act = login & type = ajax & name = 20102301025 & pass = 523523 & verify = '. $ code; echo request_by_curl ($ remote_server, $ post_string );


This is the php code that I simulated to log on to South China Normal University for an internship.

Yes !!!!!

Why does this website write the verification code to the header ??

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.