Php 使用cURL检索页面的最新版本

Php 使用cURL检索页面的最新版本,php,cookies,curl,Php,Cookies,Curl,我的站点从另一个站点拉入并发布一个计划-使用cURL检索。计划每天都在更改,但是,除非我删除服务器上的cookie文件,否则最新版本的计划不会发布到我的站点,因此我假设cookie需要更新,但不会发生 额外信息:cookie文件拥有权限644;我假设它可以在cURL创建文件时读/写,如果它不在那里的话 谢谢你的帮助 代码: 您可以尝试使用CURLOPT\u FRESH\u CONNECT TRUE强制使用新连接 curl\u setopt($curl1,CURLOPT\u FRESH\u CON

我的站点从另一个站点拉入并发布一个计划-使用cURL检索。计划每天都在更改,但是,除非我删除服务器上的cookie文件,否则最新版本的计划不会发布到我的站点,因此我假设cookie需要更新,但不会发生

额外信息:cookie文件拥有权限644;我假设它可以在cURL创建文件时读/写,如果它不在那里的话

谢谢你的帮助

代码:


您可以尝试使用
CURLOPT\u FRESH\u CONNECT TRUE
强制使用新连接

curl\u setopt($curl1,CURLOPT\u FRESH\u CONNECT,TRUE)

不过,我很好奇您的文件中包含哪些cookies。

补充 curl_setopt($ch,CURLOPT_COOKIESESSION,TRUE);
对于以上内容,现在的日程安排是最新的版本。

这真的很奇怪。我接受了你的建议,我知道每次通话都会写入cookie文件,但今天早上我看到日程表上仍然显示着昨天的信息。尝试了多个浏览器,清除了缓存,没有区别,直到我删除了cookie文件,然后用正确的时间表更新。非常奇怪!文件中有哪些cookies?他们是否指定了你正在抓取的文件的开始日期?如果其他人偶然发现了这篇文章,答案是将CURLOPT_COOKIESESSION设置为true。谢谢你的帮助!很高兴你找到了解决办法+1.你的答案
<?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);

?>
# 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