Network programming-use PHP to access the cookie passing of the same host through different pages

Source: Internet
Author: User
There are two local Apache files: a. php & amp; B. php. A. The php file first contacts the Host through curl and creates a cookie. Then pass some parameters to B. php, and then B. php will use the cookie created by a. php to contact the Host. How can this problem be achieved? There are two files on the local Apache: a.php& b.php.
a.phpFile first curlContact and create cookie.
Then pass some parameters b.php, And then b.phpUse a.phpCreated cookieContact Host.

How can this problem be achieved?

Reply content:

There are two files on the local Apache:a.php&b.php.
a.phpFile firstcurlContact and createcookie.
Then pass some parametersb.php, And thenb.phpUsea.phpCreatedcookieContact Host.

How can this problem be achieved?

Save the cookie. if your native cURL is used, it will be stored as a file.
When you try again, read the saved cookie file.

Let's take a look. It seems that you are tired.

$ Post = '_ EVENTTARGET = & __ EVENTARGUMENT = & __ VIEWSTATE ='; // initialize $ curl = curl_init (' http:///login.aspx '); $ Header = array (); $ header [] = 'host: 113. '; $ header [] = 'connection: keep-alive'; $ header [] = 'cache-Control: max-age = 0'; $ header [] = 'accept: text/html, application/xhtml + xml, application/xml; q = 0.9, image/webp, */*; q = 0.8 '; $ header [] = 'Origin: http://113 . '; $ Header [] = 'User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/100 '; $ header [] = 'content-Type: application/x-www-form-urlencoded'; $ header [] = 'referer: http:///login.aspx '; $ Header [] = 'Accept-Encoding: gzip, deflate'; $ header [] = 'Accept-Language: zh-CN, zh; q = 100 '; $ header [] = 'cookie: ASP. NET_SessionId = '. $ cookies; curl_setopt ($ curl, CURLOPT_HTTPHEADER, $ header); // do not output header information curl_setopt ($ curl, CURLOPT_HEADER, 1 ); // save to string instead of output curl_setopt ($ curl, CURLOPT_RETURNTRANSFER, 1); // post data curl_setopt ($ curl, CURLOPT_POST, 1); // request data curl_setopt ($ curl, CURLOPT_POSTFIELDS, $ post); // whether to capture the redirected page curl_setopt ($ curl, CURLOPT_FOLLOWLOCATION, 1); $ response = curl_exec ($ curl); curl_close ($ curl ); $ rs = strlen ($ response );

Why don't you directly go to require B. php at the end of a. php?

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.