尝试过这个:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://site/takelogin.php');
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, 'username=USER&password=PASS');
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$store = curl_exec ($ch);
curl_close ($ch);
一切都从login.php开始,但从goe到takelogin.php,如果用户名和密码正确,它会重定向到acc.php
<form action="takelogin.php" id="signup" method="post">
<input id="username" name="username" type="text" maxlength="25" value="">
<input id="password" name="password" type="password" maxlength="60" value="">
<input name="commit" type="submit" value="Login">
<input type="hidden" name="returnto" value="/acc.php"
即使在浏览器url栏中也尝试输入:http://site/takelogin.php?returnto=acc.php&username=USER&password=PASS
运气不好。
我的卷曲脚本缺少什么?
如果你想让curl遵循php重定向,你需要使用这个:
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
但是表单中也有"returnto"字段,在curl脚本中不使用该字段。你需要那个变量,还是它是可选的?
默认情况下,Curl不遵循重定向,有CURLOPT_FOLLOWLOCATION。
由于无法访问此登录系统,我们最多可以说登录脚本正在检查提交按钮的值,因此将commit=Login
添加到查询值中。
如果您需要为基本身份验证提供凭据,请确保在表单接收脚本中添加以下内容。
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");