我正在尝试使用 curl 访问我注册的站点的帐户,问题是登录页面有一个隐藏的身份验证输入字段,例如<input type='hidden' name='auth' value='adih2yerjh'/>
,有没有办法确保我在使用 curl 之前检查该站点的该字段提交表格?这是我的功能的模型
function login(){
$login_email = 'email';
$login_pass = 'password';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.mysite.com/login.php');
curl_setopt($ch, CURLOPT_POSTFIELDS,'email='.urlencode($login_email).'&pass='.urlencode($login_pass).'&login=Login');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3");
$page = curl_exec($ch);
echo $page;
}
编辑:每次页面加载时身份验证代码都会更改