-
- $cookie_jar = dirname(__file__)."/pic.cookie";
-
Copy code
2. Get cookies
Save cookies to file
-
-
- $url = "http://1.2.3.4/";
- $ch = curl_init();
- curl_setopt($ch, curlopt_url, $url);
- curl_setopt($ch , curlopt_header, 0);
- curl_setopt($ch, curlopt_returntransfer, true);
- curl_setopt($ch, curlopt_cookiejar, $cookie_jar);
- $content = curl_exec($ch);
- curl_close($ch);
Copy Code
3. Simulate browser to obtain verification code
The server verification code has loopholes and you can specify it yourself.
Take out the cookie and submit it to the server together, so that the server thinks it is the browser opening the login page.
-
-
- $ch = curl_init();
- curl_setopt($ch, curlopt_url, 'http://1.2.3.4/getcheckpic.action?rand=6836.185874812305');
- curl_setopt($ch , curlopt_cookiefile, $cookie_jar);
- curl_setopt($ch, curlopt_header, 0);
- curl_setopt($ch, curlopt_returntransfer, 1);
- $ret = curl_exec($ch); // bbs.it-home.org
- curl_close ($ch);
Copy code
4. Post submission
-
-
- $post = "name=2&usertype=1&passwd=asdf&logintype=1&rand=6836&imagefield.x=25&imagefield.y=7";
- $ch = curl_init();
- curl_setopt($ch, curlopt_url, "http://1.2.3.4/loginstudent.action");
- curl_setopt($ch, curlopt_header, false);
- curl_setopt($ch, curlopt_returntransfer,1);
- curl_setopt($ch, curlopt_postfields, $post) ;
- curl_setopt($ch, curlopt_cookiefile, $cookie_jar);
- $result=curl_exec($ch);
- curl_close($ch);
Copy code
5. Get data from the specified page
-
-
- $ch = curl_init();
- curl_setopt($ch, curlopt_url, "http://1.2.3.4/accountcarduser.action");
- curl_setopt($ch, curlopt_header, false );
- curl_setopt($ch, curlopt_header, 0);
- curl_setopt($ch, curlopt_returntransfer,0);
- curl_setopt($ch, curlopt_cookiefile, $cookie_jar);
- $html=curl_exec($ch);
- // var_dump ($html);
- curl_close($ch);
Copy code
The above introduces the method of php curl to simulate login by obtaining cookies, and several examples of php simulated login. I hope it will be helpful to everyone.
>>> More php simulated login articles, topic links: php simulated login php curl simulated login tutorials
|