这是我的卷曲功能。它适用于我的本地Windows机器。但是在服务器上它无法保存cookie文件(没有错误,只是没有出现cookie文件,并且程序失败了。)。权限似乎是有序的,因为我能够file_put_contents()到我试图保存cookie的文件夹。创建cookie文件失败的可能原因是什么?有人可以列出它们,以便我可以逐个检查。或者欢迎任何其他建议。
SOS
由于
define('DS',DIRECTORY_SEPARATOR) ;
if (DS == '\\') {
define ('CKFILE',"C:/cookiefile.txt" );
}
else {
define ('CKFILE',"/home/user/public_html/sitename.com/cookiefile.txt" );
}
function curl_fetch($url, $save_cookies = true, $load_cookies = true, $post_data = false, $https = false) {
file_put_contents("/home/username/public_html/sitename.com/testfile.txt", 'writable file') ;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url); // Target site
if ($load_cookies) curl_setopt($ch, CURLOPT_COOKIEFILE, CKFILE);
if ($save_cookies) curl_setopt($ch, CURLOPT_COOKIEJAR, CKFILE);
if ($https) {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
}
curl_setopt($ch, CURLOPT_REFERER, "http://www.google.com");
if ($post_data) {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
}
curl_setopt($ch, CURLOPT_TIMEOUT, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); // Follow redirects
curl_setopt($ch, CURLOPT_MAXREDIRS, 4); // Limit redirections to four
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); // Return in string
$page = curl_exec($ch);
//echo $page ;
curl_close($ch);
return $page;
}