我在我的服務器上運行以下代碼,該腳本在瀏覽器中正常工作,但是當我在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