Php 尝试使用curl登录时出现奇怪的重定向问题
正在尝试使用此网站上的curl登录: 这是我的完整脚本:Php 尝试使用curl登录时出现奇怪的重定向问题,php,Php,正在尝试使用此网站上的curl登录: 这是我的完整脚本: $ref = "http://www.indianvideogamer.com/" ; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,"http://www.indianvideogamer.com/forums/index.php?app=core&module=global&section=login&am
$ref = "http://www.indianvideogamer.com/" ;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://www.indianvideogamer.com/forums/index.php?app=core&module=global&section=login&do=process") ; // Target site
curl_setopt ($ch, CURLOPT_COOKIEFILE, "C:/cookie2-techenclave.txt");
curl_setopt($ch, CURLOPT_COOKIEJAR, "C:/cookie2-techenclave.txt");
curl_setopt($ch, CURLOPT_REFERER, $ref);
curl_setopt($ch, CURLOPT_TIMEOUT, CURL_TIMEOUT); // Timeout
curl_setopt($ch, CURLOPT_USERAGENT, WEBBOT_NAME);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, "referer=http://www.indianvideogamer.com/forums/index.php&username=cute.bandar&password=mypass");
// curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); // Follow redirects
curl_setopt($ch, CURLOPT_MAXREDIRS, 4); // Limit redirections to four
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); // Return in string
$webpage['FILE'] = curl_exec($ch);
curl_close($ch);
echo $webpage['FILE'] ;
在localhost/script.php上运行此脚本的结果是,它不会回显重定向到的页面。为什么? 尝试使用
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
这将遵循重定向。我承认这不是一个明显的重定向 但最后我还是成功了。我在URL参数中跳过了符号的URL编码。所以我的路线是:
curl_setopt($ch, CURLOPT_URL,"http://www.indianvideogamer.com/forums/index.php?app=core&module=global§ion=login&do=process") ;
顺便说一句,你确定这是整个剧本吗?我的PHP抱怨缺少
CURL\u TIMEOUT
和WEBBOT\u NAME
的定义,但这似乎并不影响登录。是CURL执行重定向,还是在服务器上点击该脚本重定向浏览器?很可能是Web服务器本身执行重定向,而不是脚本。脚本中没有重定向localhost->www.localhost的内容,但Web服务器上很可能存在重写规则或类似规则。在webpage变量中得到了什么?