简体   繁体   中英

check if remote webpage has been changed

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);


?>

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM