我在我的服务器上运行以下代码,该脚本在浏览器中正常工作,但是当我在cronjob中或通过shell以root用户身份登录时尝试它得到完全不同的输出。Cron作业有不同的输出,然后在浏览器中运行脚本
输出通过浏览器:
- 日志中,并获取网页,我想
通过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
?>
你是否以root身份运行此脚本(来自cron)? – genesis
“通过浏览器”是什么意思?我认为这是一个脚本,并通过浏览器将通过网址访问它?还有什么是cron作业命令?你有什么特权? – Steven
我以root用户身份登录并运行此命令.../usr/bin/php /var/www/vhosts/domain.co.uk/httpdocs/store/curl_test.php如果我转到http:// www。 domain.com/store/curl_test.php它的工作原理 – Stu