如何登录与curl和获得链接下载在其他网站


How to login with curl and get link download in other website

我有一个网站,我想从它得到链接下载,但这个网站要求我登录,我创建curl登录,但它不工作!这是我的代码config。

$config['id'] 		= 'dinhvanvu94@gmail.com'; // 
$config['password'] =  'nhocmiss@2'; // 

curl.php

class cURL {
var $headers;
var $user_agent;
var $compression;
var $cookie_file;
var $proxy;
	function __construct($cookies=TRUE,$cookie='cook.txt',$compression='gzip',$proxy='') {
		$this->headers[] = 'Accept: image/gif, image/x-bitmap, image/jpeg, image/pjpeg';
		$this->headers[] = 'Connection: Keep-Alive';
		$this->headers[] = 'Content-type: application/x-www-form-urlencoded;charset=UTF-8';
		$this->user_agent = 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36';
		$this->compression=$compression;
		$this->proxy=$proxy;
		$this->cookies=$cookies;
		if ($this->cookies == TRUE) $this->cookie($cookie);
	}
	function cookie($cookie_file) {
		if (file_exists($cookie_file)) {
		$this->cookie_file=$cookie_file;
		} else {
		fopen($cookie_file,'w') or $this->error('The cookie file could not be opened. Make sure this directory has the correct permissions');
		$this->cookie_file=$cookie_file;
		fclose($this->cookie_file);
		}
	}
	
	function getheader($url) {
		$process = curl_init($url);
		curl_setopt($process, CURLOPT_HTTPHEADER, $this->headers);
		curl_setopt($process, CURLOPT_HEADER, 1);
		curl_setopt($process, CURLOPT_USERAGENT, $this->user_agent);
		if ($this->cookies == TRUE) curl_setopt($process, CURLOPT_COOKIEFILE, $this->cookie_file);
		if ($this->cookies == TRUE) curl_setopt($process, CURLOPT_COOKIEJAR, $this->cookie_file);
		curl_setopt($process,CURLOPT_ENCODING , $this->compression);
		curl_setopt($process, CURLOPT_TIMEOUT, 30);
		curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);
		//curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1);
		curl_setopt($process,CURLOPT_SSL_VERIFYPEER, 0);
		curl_setopt($process,CURLOPT_CAINFO, NULL);
		curl_setopt($process,CURLOPT_CAPATH, NULL);
		$return = curl_exec($process);
		curl_close($process);
		return $return;
	}

download.php

include('start.php');
function _login()
{
	global $html, $curl, $config;
	
	preg_match('#<input type="hidden" value="(.*?)" name="fs_csrf" />#',$html,$fs_csrf);
	
	$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';
	$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))
{
	// chua dang nhap
	_login();
	
}
$link = $curl->get('https://www.fshare.vn/download/index');
echo $link;

和start.php

include('config.php');
include('curl.php');
$curl = new cURL();
这是í我的代码,它可以登录这个网站,但它没有得到链接

您的电子邮件和密码不存储在config数组中,它们在注释中。

$config['id']       = 'THIS IS WHERE YOU WRITE YOUR EMAIL'; 
$config['password'] =  'THIS IS WHERE YOU WRITE YOUR PASSWORD'; 

您正在尝试在下载。php文件中使用$curl->get()$curl->post()。这些方法没有定义。类代码是你写的吗?