2012-06-05 1 views
0

나는 사용자가 스크립트를 통해 이미지를 액세스하는 어려움을 겪고있는 질문 건너했습니다 (사용자 에이전트와 IP 주소 제외) :서버/스크립트가 cURL/file_get_contents()를 통해 사이트에 액세스하고 있는지 어떻게 알 수 있습니까? (<code>cURL</code>/<code>file_get_contents()</code> 사용)

How to save an image from url using PHP?

이미지 링크가 보인다 file_get_contents()을 요청할 때 403 오류를 반환합니다. 그러나 cURL에서 더 자세한 오류가 반환됩니다.

시스템에 대한 액세스가 거부되었습니다. 정말로 액세스하려면 엔진을 끄거나 서핑 프록시, 가짜 IP를 해제하십시오. 프록시 또는 허용되지 않음 웹 도구 침입 방지 시스템.

빈 민 온라인 데이터 서비스는 2008 @ -

2012 나는 또한 컬을 요청 자신과 주변 하구 후 동일한 이미지에 액세스하지 못했습니다. 성공적으로 이미지에 액세스 할 수있는 정확한 브라우저 user-agent로 사용자 에이전트를 변경해 보았습니다. 나는 (분명히) 내 브라우저와 같은 IP 주소를 사용하는 내 개인 로컬 서버에서도 스크립트를 시도했다 ... 내가 아는 한 사용자 에이전트와 IP 주소는 상황에 맞지 않는다.

누군가 다른 사람이 요청을 수행하는 스크립트를 어떻게 찾을 수 있습니까?

자세히 알아보기, 이것은 별 효과가 없습니다. 난 그냥 궁금해서 xD

+1

도둑질하지 마십시오, 문제 해결 :-) –

+0

@ 대각선 BTW, 이것은 미치광이가 아닙니다. 나는 단지 호기심이 xD' –

+0

왜냐하면 당신이 그것을 말하기 때문에, 나는 그것이 당신을 믿는다는 것을 의미하지 않는다. –

답변

6

실제로 JavaScript에 의해 설정되고 원래 이미지로 리디렉션되는 쿠키입니다. 문제는 curl/fgc가 html을 파싱하지 않고 curl이 쿠키 항아리에 저장할 서버가 설정 한 쿠키 만 설정한다는 것입니다.

는 리디렉션하기 전에 얻을 코드, 그것은 어떤 이름으로 자바 스크립트를 통해 쿠키를 만들지 만입니다 같이 location.href 값으로 :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<HEAD> 
<TITLE>http://phim.xixam.com/thumb/giotdang.jpeg</TITLE> 
<meta http-equiv="Refresh" content="0;url=http://phim.xixam.com/thumb/giotdang.jpeg"> 
</HEAD> 
<script type="text/javascript"> 
window.onload = function checknow() { 
var today = new Date(); 
var expires = 3600000*1*1; 
var expires_date = new Date(today.getTime() + (expires)); 
var ua = navigator.userAgent.toLowerCase(); 
if (ua.indexOf("safari") != -1) { document.cookie = "location.href"; } else { document.cookie = "location.href;expires=" + expires_date.toGMTString(); } 
} 
</script> 
<BODY> 
</BODY></HTML> 

그러나 모든 때문에 미리 설정에 의해, 손실되지 않습니다/쿠키를 위조하면이 보안 조치를 피할 수 있습니다 (모든 종류의 보안을 위해 쿠키를 사용하는 것이 나쁜 이유).

# Netscape HTTP Cookie File 
# http://curl.haxx.se/rfc/cookie_spec.html 
# This file was generated by libcurl! Edit at your own risk. 

phim.xixam.com FALSE /thumb/ FALSE 1338867990  location.href 

그래서 같은 보일 것이다 적어서 컬 스크립트 cookie.txt : 크롤러를 중지 할 수있는 유일한 방법

<?php 
function curl_get($url){ 
    $return = ''; 
    (function_exists('curl_init')) ? '' : die('cURL Must be installed!'); 

    //Forge the cookie 
    $expire = time()+3600000*1*1; 
    $cookie =<<<COOKIE 
# Netscape HTTP Cookie File 
# http://curl.haxx.se/rfc/cookie_spec.html 
# This file was generated by libcurl! Edit at your own risk. 

phim.xixam.com FALSE /thumb/ FALSE $expire  location.href 

COOKIE; 
    file_put_contents(dirname(__FILE__).'/cookie.txt',$cookie); 

    //Browser Masquerade cURL request 
    $curl = curl_init(); 
    $header[0] = "Accept: text/xml,application/xml,application/json,application/xhtml+xml,"; 
    $header[0] .= "text/html;q=0.9,text/plain;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: "; 

    curl_setopt($curl, CURLOPT_COOKIEJAR, dirname(__FILE__).'/cookie.txt'); 
    curl_setopt($curl, CURLOPT_COOKIEFILE, dirname(__FILE__).'/cookie.txt'); 
    curl_setopt($curl, CURLOPT_URL, $url); 
    curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 5.1; rv:5.0) Gecko/20100101 Firefox/5.0 Firefox/5.0'); 
    curl_setopt($curl, CURLOPT_HTTPHEADER, $header); 
    curl_setopt($curl, CURLOPT_HEADER, 0); 
    //Pass the referer check 
    curl_setopt($curl, CURLOPT_REFERER, 'http://xixam.com/forum.php'); 
    curl_setopt($curl, CURLOPT_ENCODING, 'gzip,deflate'); 
    curl_setopt($curl, CURLOPT_AUTOREFERER, true); 
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); 
    curl_setopt($curl, CURLOPT_TIMEOUT, 30); 
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); 

    $html = curl_exec($curl); 
    curl_close($curl); 
    return $html; 
} 

$image = curl_get('http://phim.xixam.com/thumb/giotdang.jpeg'); 

file_put_contents('test.jpg',$image); 
?> 

가 데이터베이스에있는 모든 방문자의 IP를 기록하는 것입니다 ip 당 방문수를 기준으로 값을 증가시킨 다음 1 주일에 한 번 ip로 상위 히트 수를 확인한 다음 ip의 역방향 조회를 수행하고 호스팅 제공 업체가 방화벽이나 htaccess에서 차단하는지 확인합니다 , 그때 그쪽으로 어떤 장애물이라도 공개적으로 사용 가능하다면 리소스 요청을 실제로 중단 할 수는 없습니다.

희망이 있습니다.

+0

와우, 위의 내 의견을 올렸을 때 솔직히 일종의 파악이 아니라고 생각했으며 실제로 작동하지 않는 실제 이유는 아마도 OP가 간과 한 것이었을 것입니다. 그것은 몇 가지 훌륭한 후속 조치와 테스트입니다! 잘하면 OP가 받아 들일 것이고 당신의 대답을 upvote, 당신은 분명히 나와 upvote를 얻을! –

+0

고마워, 네가 그 얌 쿠키 맞았 어. –

관련 문제