php与curl通过php代码登录网站


php with curl to login into website through php code

我收到执行成功消息,但它没有重定向到错误的网页:

Forbidden: You don't have permission to access /myaccount.php on this server.

代码:

$username ='xyz@gmail.com';
$password ='******';
$loginUrl1 ='http://www.zopnow.com/myaccount.php';
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $loginUrl1);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS,"email=$username&password=$password");
// to ignore all cookies using libcurl
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
$store1= curl_exec($ch);
echo "Executed Successfully with loginUrl1 ".$store1;

curl_close($ch);

问题似乎出在您使用的登录URL上。

登录表单不提交给myaccount.php脚本,而是提交给login.php脚本。

尝试更改

$loginUrl1 ='http://www.zopnow.com/myaccount.php';

$loginUrl1 ='http://www.zopnow.com/login.php';

同时尝试添加

&redirect=myaccount.php?&remember=true添加到post字段。

此外,这个登录页面没有加密,所以要小心使用您在其他地方使用的帐户名和密码。如果你已经这样做了,可以考虑在其他地方更改你的密码。