How to change a common form login to a phpcurl simulated form Login & lt; form & nbsp; method = "post" & nbsp; action = "2.php" & gt; & nbsp; & nbsp; Username: & nbsp; & lt; input & nbsp; type = 'text' & nbsp; name = "lo how to change normal form login to php curl 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 = '000000'; // logon 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 );
------ 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
------ Solution --------------------
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 );
------ Solution --------------------
#1. didn't you say that?
Echo curl_exec ($ ch );
How can you do this without outputting results?
Script
CSDN Forum homepage-CSDN. NET
Script
$ (Function (){
Main_page_js.index_page ();
});
Script
<Br/> & nbsp; <body> <br/> & nbsp; </body> <br/> & nbsp;