로그인해야하는 웹 사이트에 로그인 할 때 이미지를 다운로드하는 데 문제가 있습니다. 이미지는 사용자가 사이트에 로그인했을 때만 볼 수 있지만 탭/새 창 (오류 페이지로 리디렉션 됨)에 위치를 복사하면 브라우저에서 직접 볼 수 없습니다. 따라서 포함하는 폴더는 .htaccess-ed가됩니다.로그인했을 때만 이미지 저장 가능
어쨌든 아래에있는 코드를 사용하면 로그인하여 HTML 콘텐츠를 얻을 수 있습니다. 이미지는 잘 보이지 않지만 도움이 필요한 곳입니다! 아래
<?
// curl.php
class Curl {
public $cookieJar = "";
public function __construct($cookieJarFile = 'cookies.txt') {
$this->cookieJar = $cookieJarFile;
}
function setup() {
$header = array();
$header[0] = "Accept: text/xml,application/xml,application/xhtml+xml,";
$header[0] .= "text/html;q=0.9,text/plain;q=0.8,image/gif;q=0.8,image/x-bitmap;q=0.8,image/jpeg;q=0.8,image/png,*/*;q=0.5";
$header[] = "Cache-Control: max-age=0";
$header[] = "Connection: keep-alive";
$header[] = "Keep-Alive: 300";
$header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
$header[] = "Accept-Language: en-us,en;q=0.5";
$header[] = "Pragma: "; // browsers keep this blank.
curl_setopt($this->curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.8.1.7) Gecko/20070914 Firefox/2.0.0.7');
curl_setopt($this->curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($this->curl, CURLOPT_COOKIEJAR, $this->cookieJar);
curl_setopt($this->curl, CURLOPT_COOKIEFILE, $this->cookieJar);
curl_setopt($this->curl, CURLOPT_AUTOREFERER, true);
curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true);
}
function get($url) {
$this->curl = curl_init($url);
$this->setup();
return $this->request();
}
function getAll($reg, $str) {
preg_match_all($reg, $str, $matches);
return $matches[1];
}
function postForm($url, $fields, $referer = '') {
$this->curl = curl_init($url);
$this->setup();
curl_setopt($this->curl, CURLOPT_URL, $url);
curl_setopt($this->curl, CURLOPT_POST, 1);
curl_setopt($this->curl, CURLOPT_REFERER, $referer);
curl_setopt($this->curl, CURLOPT_POSTFIELDS, $fields);
return $this->request();
}
function getInfo($info) {
$info = ($info == 'lasturl') ? curl_getinfo($this->curl, CURLINFO_EFFECTIVE_URL) : curl_getinfo($this->curl, $info);
return $info;
}
function request() {
return curl_exec($this->curl);
}
}
?>
그리고
그것을 사용하는 페이지입니다.<?
// data.php
include('curl.php');
$curl = new Curl();
$url = "http://domain.com/login.php";
$newURL = "http://domain.com/go_here.php";
$username = "user";
$password = "pass";
$fields = "user=$username&pass=$password";
// Calling URL
$referer = "http://domain.com/refering_page.php";
$html = $curl->postForm($url, $fields, $referer);
$html = $curl->get($newURL);
echo $html;
?>
나는 $ NEWURL에 이미지에 대한 직접 URL을 퍼팅 시도했지만 그 이미지를 얻을하지 않습니다 - 그것은 단순히 폴더를 직접 볼 수 없습니다 때문에 말하는 오류를 반환합니다. 나는 여러 가지 방법으로 위의 것을 시도했지만 이미지를 얻는 데 성공하지 못했다. 기본적으로 오류 405 및/또는 406 (그러나 원하는 이미지가 아님)을 통해 화면을 가져올 수 있었다.
도움이 될 것입니다.