我需要創建一個登錄到遠程站點的php腳本,然後在該站點上下載一個csv文件。我搜遍了所有,並沒有找到任何我需要的東西。目前我只有以下代碼可以讓我登錄到遠程站點。PHP登錄到遠程站點並下載csv
<?php
$username="";
$password="";
$url='';
$cookie="";
$postdata = 'email='.$username.'&pass='.$password;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_REFERER, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($ch, CURLOPT_POST, true);
$result = curl_exec($ch);
echo $result;
curl_close($ch);
>
你嘗試過使用EXEC()命令? – artsylar
取決於您需要如何確定要下載哪個csv文件。你事先知道URL嗎?或者每次登錄時都會更改它? – Stobor
@Stobor我知道網址之前它永不改變。 – dewbop12