[英]Retrieving most recent version of page with cURL
我的站點從另一個站點拉入並發布了時間表-使用cURL檢索。 日程安排每天都會更改,但是,除非刪除服務器上的cookie文件,否則不會將日程安排的最新版本發布到我的站點,因此我認為cookie需要更新,但是沒有發生。
額外信息:cookie文件具有權限644; 我假設它可以被讀取/寫入,因為cURL創建文件(如果不存在)。
感謝您的任何幫助!
碼:
<?php
$login_url = 'https://example.com';
//These are the post data username and password
$post_data = 'username=user&password=password&external_login=0&action=login';
//Create a curl object
$ch = curl_init();
//Set the useragent
$agent = $_SERVER["HTTP_USER_AGENT"];
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
//Set the URL
curl_setopt($ch, CURLOPT_URL, $login_url );
//This is a POST query
curl_setopt($ch, CURLOPT_POST, 1 );
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
//Set the post data
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
//We want the content after the query
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//Follow Location redirects
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
/*
Set the cookie storing files
Cookie files are necessary since we are logging and session data needs to be saved
*/
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
//Execute the action to login
$postResult = curl_exec($ch);
$geturl='https://example.com/schedule';
curl_setopt($ch, CURLOPT_URL, $geturl);
curl_exec($ch);
if(curl_exec($ch) === false)
{
echo 'Error: ' . curl_error($ch);
}
curl_setopt($ch, CURLOPT_URL, $geturl);
$schedule = curl_exec($ch);
echo $schedule;
curl_close($ch);
?>
這是cookie文件的內容:
# Netscape HTTP Cookie File
# http://curl.haxx.se/rfc/cookie_spec.html
# This file was generated by libcurl! Edit at your own risk.
example.com FALSE / FALSE 0 code1234 codexxxxxxxxxx
example.com FALSE /id/ FALSE 12345678 display_mobile_version_1620 0
添加了curl_setopt($ ch,CURLOPT_COOKIESESSION,TRUE); 到上面的內容,現在時間表正在更新最新版本。
您可以嘗試使用CURLOPT_FRESH_CONNECT TRUE
強制使用新連接。
curl_setopt($curl1, CURLOPT_FRESH_CONNECT, TRUE);
不過,我很好奇文件中包含哪些Cookie。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.