PHP obtains Cookie simulated Login

Source: Internet
Author: User

Keywords:CURLCookie CURLOPT_COOKIEJAR CURLOPT_COOKIEFILE simulate PHP Login
Author: Fang Times studio
Original article: http://www.cnblogs.com/txw1958/p/php-cookie-login.html

 

1. Define the Cookie storage path

Absolute path is required

 = ()."/pic.cookie";

 

Ii. obtain cookies

Store cookies into files

 = "http://1.2.3.4/" =, CURLOPT_URL, , CURLOPT_HEADER, 0, CURLOPT_RETURNTRANSFER, , CURLOPT_COOKIEJAR,  = curl_exec();

 

3. simulate a browser to obtain the verification code

The server verification code has a vulnerability and can be specified by yourself.

Extract the cookie and submit it to the server so that the server can open the login page as a browser.

 =, CURLOPT_URL, 'http://1.2.3.4/getCheckpic.action?rand=6836.185874812305', CURLOPT_COOKIEFILE, , CURLOPT_HEADER, 0, CURLOPT_RETURNTRANSFER, 1 = curl_exec();

 

Iv. POST submission

 = "name=2&userType=1&passwd=asdf&loginType=1&rand=6836&imageField.x=25&imageField.y=7" =, CURLOPT_URL, "http://1.2.3.4/loginstudent.action", CURLOPT_HEADER, , CURLOPT_RETURNTRANSFER,1, CURLOPT_POSTFIELDS, , CURLOPT_COOKIEFILE, =curl_exec();

 

5. Get data on the specified page

 =, CURLOPT_URL, "http://1.2.3.4/accountcardUser.action", CURLOPT_HEADER, , CURLOPT_HEADER, 0, CURLOPT_RETURNTRANSFER,0, CURLOPT_COOKIEFILE, =curl_exec(curl_close();

 

 

 

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.