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 孟德尔随机化结果不一致
  • ¥20 求用stm32f103c6t6在lcd1206上显示Door is open和password:
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法