Remote login with curl (php)
I try to submit login form with phpcommand: curl, but it doesn't work. The fields form are two: email and psw. The problem is that if I use urlencode to field email it return the error: "incorrect format email!", while if I not use the urlencode there aren't response.
This is the code without urlencode:
$url = 'myurl'开发者_如何学C;
$fields = array(
'login_email'=> 'myemail@gmail.com',
'login_passwd'=> 'mypsw',
'remember_me' => '1'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); // Return page in string
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,$fields);
$page = curl_exec($ch);
echo $page;
//close connection
curl_close($ch);
Are you sure there's no response? Many login systems simply do a redirect to some other page if the login is successful. Try adding
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
which'd let CURL obey the redirect and fetch whatever page the server's sending you off to.
Alternatively, you can use the CURLOPT_HEADER
option to include the HTTP headers in the response returned into your $page
value and see what's going on there.
精彩评论