我将其发布为php / curl,但对任何有效的解决方案都是开放的。
example.com/login.asp
在登录表单中包含隐藏值:
input type="hidden" name="security" value="123456789abcdef"
我尝试使用curl来获取这个额外的安全值并将其包含到另一个curl调用中,但是在第一次curl之后值已更改。我已阅读相关帖子,建议使用php file_get_contents
,但它不适用于特定网站。
目前的php curl看起来像这样:
function curling ($websitehttps,$postfields,$cookie,$ref,$follow) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $websitehttps);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded', 'Connection: Close'));
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1");
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
if ($cookie != "") {
curl_setopt($ch, CURLOPT_COOKIE,$cookie);
}
if ($postfields != "") {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$postfields);
}
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $follow);
curl_setopt($ch, CURLOPT_AUTOREFERER,TRUE);
curl_setopt($ch, CURLOPT_REFERER, $ref);
curl_setopt($ch, CURLOPT_FAILONERROR, TRUE);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
我需要在帖子字段($ postfields)中使用额外的安全码,它应该类似于以下内容:
ref=https%3A%2F%2Fexample.com%2F&security=123456789abcdef
有办法做到这一点吗?
答案 0 :(得分:0)
在两个单独的卷曲会话中添加一些额外的行解决了这个问题。
添加到第一个卷曲会话的行:
curl_setopt ($ch, CURLOPT_COOKIEJAR, '/tmp/cookie.txt');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
这些添加在tmp文件夹中创建了一个cookie文件。
添加到第二个卷曲会话的行:
curl_setopt ($ch, CURLOPT_COOKIEFILE, '/tmp/cookie.txt');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
在这里,使用cookie文件中的信息在登录页面上获取相同的安全代码。
another website中描述的解决方案也可能有效。就我而言,服务器设置不允许我使用它。