我想编写一个脚本来登录使用PHP中的curl。我编写了这段代码,当我尝试使用这个脚本时,所有时间都显示消息:"用户名或密码不正确",但是如果我给这个用户名并通过,我将登录。
我不知道这个系统需要什么,我的代码现在看起来像:
$curl=curl_init("http://plemiona.pl/page/auth");
curl_setopt($curl,CURLOPT_HEADER,1);
curl_setopt($curl,CURLOPT_USERAGENT,"Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0");
curl_setopt($curl,CURLOPT_REFERER,"http://plemiona.pl/");
curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl, CURLOPT_FAILONERROR, TRUE);
curl_setopt($curl, CURLOPT_COOKIESESSION, TRUE);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_COOKIEFILE, "D:\cookies.txt");
curl_setopt($curl, CURLOPT_COOKIEJAR, "D:\cookies.txt");
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, Array("Content-Type: application/x-www-form-urlencoded",
"X-Requested-With: XMLHttpRequest",
"POST /page/auth HTTP/1.1",
"Host: www.plemiona.pl",
"Accept: */*",
"Accept-Language: pl,en-US;q=0.7,en;q=0.3",
"Content-Length: 48"));
curl_setopt($curl, CURLOPT_POST, true);
$postVars = array('username' => 'username',
'password' => 'pass',
'remember' => '0',);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postVars);
$dw=curl_exec($curl);
echo $dw;
当我尝试手动登录时,firefox http标题将显示:
使用curl发送POST后我的文件与cookie:
.plemiona.pl TRUE / FALSE 1520687485 cid 705415657
没什么:(
我可能需要使用正确的SSL证书:curl_setopt($ curl,CURLOPT_SSL_VERIFYPEER,TRUE)? 或者我应该搜索什么来修复它?