How to change a common form login to a phpcurl simulated form login
2. php
header('Content-Type:text/html;Charset=utf-8');if ($_POST['loginname'] == 'lee' && $_POST['loginpass'] == '123456') { header('location:http://bbs.csdn.net');} else { }
How can I modify this form to simulate login? why is it wrong?
Create a new 1.php
Header ('content-type: text/html; Charset = utf-8 '); $ user = 'Lil'; // login username $ pass = '2016 '; // login password $ post_fields = "loginname = {$ user} & loginpass = {$ pass}"; $ ch = curl_init (); curl_setopt ($ ch, CURLOPT_URL, 'http: // localhost/2. php '); curl_setopt ($ ch, CURLOPT_POST, 1); curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ post_fields); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 ); curl_exec ($ ch); curl_close ($ ch );
Reply to discussion (solution)
Echo curl_exec ($ ch );
In addition, your 2. php is redirected and no content is returned.
Change to echo file_get_contnets ('Location: http://bbs.csdn.net '); try
Header ('Location: http://bbs.csdn.net ');
Http header
HTTP/1.1 302 Found
Date: Wed, 26 Feb 2014 09:16:38 GMT
Location: http://bbs.csdn.net
Content-Length: 0
Content-Type: text/html; Charset = utf-8
Don't you follow the jump?
Curl_setopt ($ ch, CURLOPT_FOLLOWLOCATION, true );
Header ('Location: http://bbs.csdn.net ');
Http header
HTTP/1.1 302 Found
Date: Wed, 26 Feb 2014 09:16:38 GMT
Location: http://bbs.csdn.net
Content-Length: 0
Content-Type: text/html; Charset = utf-8
Don't you follow the jump?
Curl_setopt ($ ch, CURLOPT_FOLLOWLOCATION, true );
Thanks for your help. I changed it to this.
1. php
Header ('content-type: text/html; Charset = utf-8 '); $ user = 'Lil'; // login username $ pass = '2016 '; // login password $ post_fields = "loginname = {$ user} & loginpass = {$ pass}"; $ ch = curl_init (); curl_setopt ($ ch, CURLOPT_URL, 'http: // localhost/2. php '); curl_setopt ($ ch, CURLOPT_POST, 1); curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ post_fields); curl_setopt ($ ch, expires, 1); curl_setopt ($ ch, CURLOPT_FOLLOWLOCATION, true); curl_exec ($ ch); curl_close ($ ch );
2. php
header('Content-Type:text/html;Charset=utf-8');if ($_POST['loginname'] == 'lee' && $_POST['loginpass'] == '123456') { header('location:http://bbs.csdn.net');} else { }
The execution of 1.php is still blank and the redirection is not implemented.
#1. didn't you say that?
Echo curl_exec ($ ch );
How can you do this without outputting results?