我在我的服务器上运行以下代码,该脚本在浏览器中运行良好但是当我在cronjob中尝试或通过以root身份登录的shell时,我得到一个完全不同的输出。
通过浏览器输出:
通过shell / cron输出:
我正在使用red hat linux 5
<?php
$url = "http://www.domain.com/shopper_lookup.asp"; // the url where to send the request
$fields_send = 'shopper_username=USERNAME&shopper_password=PASSWORD&Validate=1';
$agent = "Opera/9.63 (Windows NT 5.1; U; en-GB) Presto/2.1.1";
$reffer = "http://www.domain.com/login.html";
$cookie_file_path = "/var/www/vhosts/domain.co.uk/httpdocs/store/cookie"; // Cookie File Path with CHMOD 777
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$fields_send);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_REFERER, $reffer);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
$result_source = curl_exec($ch);
var_dump($ch);
echo $result_source;
$url = "http://www.domain.com/receipt.asp?ms=&order_id=ordernumber"; // the url where to send the request
$agent = "Opera/9.63 (Windows NT 5.1; U; en-GB) Presto/2.1.1";
$reffer = "http://www.domain.com/contents.asp?ms=";
$cookie_file_path = "/var/www/vhosts/domain.co.uk/httpdocs/store/cookie"; // Cookie File Path with CHMOD 777
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_GET, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_REFERER, $reffer);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
$result_source = curl_exec($ch);
echo $result_source; // Print the result page
?>
答案 0 :(得分:0)
首先检查命令的输出,如果你作为你的网络用户(通常是www数据)执行
su www-data /usr/bin/php /var/www/vhosts/domain.co.uk/httpdocs/store/curl_test.php
如果可行,那么这是一个权限错误,因此请确保用户正在运行cron作业,因为可以写入文件“/var/www/vhosts/domain.co.uk/httpdocs/store/cookie”。