0
我有一個網站我想要從它下載鏈接,但本網站要求我登錄,並且使用curl創建登錄,但它不起作用! 這是我的代碼 的config.php如何使用curl登錄並在其他網站下載鏈接
$config['id'] \t \t = '[email protected]'; //
$config['password'] = '[email protected]'; //
curl.php
class cURL {
var $headers;
var $user_agent;
var $compression;
var $cookie_file;
var $proxy;
\t function __construct($cookies=TRUE,$cookie='cook.txt',$compression='gzip',$proxy='') {
\t \t $this->headers[] = 'Accept: image/gif, image/x-bitmap, image/jpeg, image/pjpeg';
\t \t $this->headers[] = 'Connection: Keep-Alive';
\t \t $this->headers[] = 'Content-type: application/x-www-form-urlencoded;charset=UTF-8';
\t \t $this->user_agent = 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36';
\t \t $this->compression=$compression;
\t \t $this->proxy=$proxy;
\t \t $this->cookies=$cookies;
\t \t if ($this->cookies == TRUE) $this->cookie($cookie);
\t }
\t function cookie($cookie_file) {
\t \t if (file_exists($cookie_file)) {
\t \t $this->cookie_file=$cookie_file;
\t \t } else {
\t \t fopen($cookie_file,'w') or $this->error('The cookie file could not be opened. Make sure this directory has the correct permissions');
\t \t $this->cookie_file=$cookie_file;
\t \t fclose($this->cookie_file);
\t \t }
\t }
\t
\t function getheader($url) {
\t \t $process = curl_init($url);
\t \t curl_setopt($process, CURLOPT_HTTPHEADER, $this->headers);
\t \t curl_setopt($process, CURLOPT_HEADER, 1);
\t \t curl_setopt($process, CURLOPT_USERAGENT, $this->user_agent);
\t \t if ($this->cookies == TRUE) curl_setopt($process, CURLOPT_COOKIEFILE, $this->cookie_file);
\t \t if ($this->cookies == TRUE) curl_setopt($process, CURLOPT_COOKIEJAR, $this->cookie_file);
\t \t curl_setopt($process,CURLOPT_ENCODING , $this->compression);
\t \t curl_setopt($process, CURLOPT_TIMEOUT, 30);
\t \t curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);
\t \t //curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1);
\t \t curl_setopt($process,CURLOPT_SSL_VERIFYPEER, 0);
\t \t curl_setopt($process,CURLOPT_CAINFO, NULL);
\t \t curl_setopt($process,CURLOPT_CAPATH, NULL);
\t \t $return = curl_exec($process);
\t \t curl_close($process);
\t \t return $return;
\t }
的download.php
include('start.php');
function _login()
{
\t global $html, $curl, $config;
\t
\t preg_match('#<input type="hidden" value="(.*?)" name="fs_csrf" />#',$html,$fs_csrf);
\t
\t $data = 'fs_csrf=' . $fs_csrf[1] . '&LoginForm%5Bemail%5D=' . urlencode($config['id']). '&LoginForm%5Bpassword%5D=' . urlencode($config['password']) . '&LoginForm%5BrememberMe%5D=0&LoginForm%5BrememberMe%5D=1&yt0=%C4%90%C4%83ng+nh%E1%BA%ADp';
\t $curl->post('https://www.fshare.vn/login',$data);
}
$html = $curl->get('https://www.fshare.vn/file/TM5MQ3VX2T');
if(!preg_match('#<a style="cursor: pointer;color: \#999999;" title="(.*?)"#', $html, $acc))
{
\t // chua dang nhap
\t _login();
\t
}
$link = $curl->get('https://www.fshare.vn/download/index');
echo $link;
和start.php
include('config.php');
include('curl.php');
$curl = new cURL();
希望他們不是合法的細節 – 2015-07-21 08:11:45