dongshao8471 2013-05-26 23:43
浏览 41

远程登录并使用PHP中的cURL显示内容

I am using cURL in PHP to login to a remote server of mine. I have successfully logged in the remote URL but I cannot seem to display the content of that page. Here is my code so far:

<?php

$username = 'Blah';
$password = 'BlahBlah';

$ch = curl_init();
$postdata="email=$username&password=$password";
curl_setopt ($ch, CURLOPT_URL,"http://www.example.com/login.php");
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_HEADER, true);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt ($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
curl_setopt ($ch, CURLOPT_REFERER, "http://www.example.com/login.php");
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt ($ch, CURLOPT_POST, 1);
$result = curl_exec($ch);

curl_setopt($ch, CURLOPT_URL, "http://www.example.com/User/Home.php") ;
$result2 = curl_exec($ch) ;

echo $result2 ;

curl_close($ch);

?>

When I try echoing $result2, nothing is there. Nothing is printed to the screen. What do I need to do in order to have the content printed to the screen?

Here is the HTTP Header output:

HTTP/1.1 302 Moved Temporarily Date: Sun, 26 May 2013 23:46:40 GMT Server: Apache/2.2.23 (Unix) mod_ssl/2.2.23 OpenSSL/0.9.8e-fips-rhel5 mod_bwlimited/1.4 Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache Set-Cookie: current_page=Home.php; expires=Wed, 24-May-2023 23:46:40 GMT Location: http://www.example.com/?redirected=3 Vary: Accept-Encoding,User-Agent Content-Length: 0 Content-Type: text/html HTTP/1.1 200 OK Date: Sun, 26 May 2013 23:46:40 GMT Server: Apache/2.2.23 (Unix) mod_ssl/2.2.23 OpenSSL/0.9.8e-fips-rhel5 mod_bwlimited/1.4 Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache Vary: Accept-Encoding,User-Agent Transfer-Encoding: chunked Content-Type: text/html
  • 写回答

2条回答 默认 最新

  • drogon982007 2013-05-26 23:46
    关注

    It probably isn't following redirects. use:

    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型
  • ¥15 深度学习中的画图问题
  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条
  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件
  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了
  • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
  • ¥188 需要修改一个工具,懂得汇编的人来。