douche1936 2013-06-20 04:26
浏览 23
已采纳

检查远程网页是否已更改

My PHP script does the following

  1. It logins to a remote server with login and password using CURL, which works Great. echo $result; shows the logged in page contents.
  2. Secondly what it does is to access a inner page ( which needs a person to be logged in ) and check if the page is remotely changed( updated) or not using CURL.

The error i am getting is "Access denied" in Part 2 of the code below, i think the Cookies is not persisting throughout the session? Is that the problem what changes should i do in the code.

<?
//Part 1
$username="username; 
$password="pwd"; 
$url="http://abc.com/home?q=login&destination=filmmaker%2Fhome";
$cookie="cookie.txt"; 

$postdata = "name=".$username."&pass=".$password."&form_id=user_login&edit-name=".$username."&remember_me=1"; 



$ch = curl_init(); 
curl_setopt ($ch, CURLOPT_URL, $url); 
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, $cookie); 
curl_setopt ($ch, CURLOPT_COOKIEFILE, $cookie); 
curl_setopt ($ch, CURLOPT_REFERER, $url); 

curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata); 
curl_setopt ($ch, CURLOPT_POST, 1); 
$result = curl_exec ($ch); 

echo $result;  

//Part 2

$curl = curl_init("http://abc.com/filmmaker/home");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_NOBODY, true);
curl_setopt($curl, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FILETIME, true);
$result = curl_exec($curl);

if ($result === false) {
    die (curl_error($curl)); 
}

$timestamp = curl_getinfo($curl, CURLINFO_FILETIME);
if ($timestamp != -1) { //otherwise unknown
    echo date("Y-m-d H:i:s", $timestamp); //etc
}
curl_close($ch);


?>
  • 写回答

1条回答 默认 最新

  • dongwu9972 2013-06-20 04:35
    关注

    Part 2 needs:

    curl_setopt($curl, CURLOPT_COOKIEFILE, $cookie);
    

    This will send the cookies that were saved by the CURLOPT_COOKIEJAR option in Part 1.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 python变量和列表之间的相互影响
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)