dou91855 2011-03-18 16:57
浏览 85

尝试使用curl登录时出现奇怪的重定向问题

Trying to login using curl on this site: http://www.indianvideogamer.com.

This is my complete script:

        $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'] ;

the result of running this script on localhost/script.php is that instead of echoing the page it redirects to http://www.localhost/script.php . Why ?

  • 写回答

2条回答 默认 最新

  • dryift6733 2011-03-18 17:07
    关注

    Try using

    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    

    This will follow redirects.

    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置