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();