dongqiyou0303 2009-01-22 13:11
浏览 12

为什么我的Gmail登录不能使用PHP和CURL?

I'm implementing one project using PHP, in that I want to login into a page automatically . The code is below.

$ch = curl_init();
$postdata="Email=$username&Passwd=$password&continue=https://www.mail.google.com";
curl_setopt ($ch, CURLOPT_URL,"https://www.google.com");
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $gacookie);
curl_setopt ($ch, CURLOPT_COOKIEFILE, $gacookie);
curl_setopt ($ch, CURLOPT_REFERER, 'https://www.google.com');
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt ($ch, CURLOPT_POST, 1);
$AskApache_result = curl_exec ($ch);
curl_close($ch);
echo $AskApache_result;
unlink($gacookie);
?>

But it won't work. Any ideas?

  • 写回答

2条回答 默认 最新

  • douliang2935 2009-01-22 13:20
    关注

    First of all: "it won't work" does not give us much information and context to help you solving the problem.

    To get your questions answered, please try to supply details, for example:

    • What specific part is not working?
    • Do you get any error messages?
    • What operating system does you code run on?

    It also helps to use a more descriptive question title. "PHP and CURL" does not give us much relevant information, whereas "How to solve error x123 when executing a CURL request" would be much more helpful.

    Anyway. Looking at your code, there's at least one error:

    curl_setopt ($ch, CURLOPT_REFERER, 'https://www.google.com");
    

    should be:

    curl_setopt ($ch, CURLOPT_REFERER, "https://www.google.com");
    

    Clarification: the third parameter starts with a single quote and ends with a double quote.

    评论

报告相同问题?

悬赏问题

  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP