.htaccess 파일에 추가
php_flag allow_url_fopen on
로딩페이지소스
ini_set('user_agent', $_SERVER[HTTP_USER_AGENT]);
simplexml_load_file("http://도메인1.com/loding.xml");
xml파일을 로딩할때 사용하는 함수입니다
simplexml_load_file("loding.xml");
loding.xml 을 로딩해서 사용할수 있습니다
그런데 외부 주소의 xml 파일을 로딩할때 안되는경우가 있습니다
simplexml_load_file("http://도메인.com/loding.xml");
이런식으로 http://도메인.com/loding.xml 외부 주소를 로딩할때 안되는경우가 있습니다
이때 외부에 있는 파일을 가져올수 있는지 확인을 해봐야 합니다
만약 사용할수 없게 되었다면
.htaccess 파일에
php_flag allow_url_fopen on
추가하면 사용가능해집니다
이랬는데도 아되는경우가 있습니다
예를 들어
simplexml_load_file("http://도메인.com/loding.xml");주소는 되는데
simplexml_load_file("http://도메인1.com/loding.xml");주소가 되지 않을때가 있습니다
모든 소스와
http://도메인.com/loding.xml
http://도메인1.com/loding.xml
주소의 xml 도 동일한데 안될때는
http://도메인1.com 도메인에서 차단되는경우가 있습니다
이때 차단이유가 user_agent 부분때문인경우가 있습니다
클라이언트 브라우저 정보를 나타내는 부분인데
예를 들어 Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.82 Safari/537.36 이러한 정보입니다
이정보가 재대로 넘어가지 않을경우 정상처리 되지 않는경우가 있습니다
이부분을 처리하기위해선
ini_set('user_agent', $_SERVER[HTTP_USER_AGENT]);
simplexml_load_file("http://도메인1.com/loding.xml");
이렇게 넘기거나
ini_set('user_agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.82 Safari/537.36');
simplexml_load_file("http://도메인1.com/loding.xml");
직접값을 넣어 넘기는 방법이 있습니다
다시한번 정리하면
외부 xml파일이나 크롤링이 안될때
1).htaccess 파일에 php_flag allow_url_fopen on 추가
2)로딩하는 페이지에 ini_set('user_agent',$_SERVER[HTTP_USER_AGENT]) 를 추가해 user_agent 부분을 재정의 합니다
이렇게 해도 안되는경우
아이피,모듈등을 통해 막은 경우도 있긴합니다
의견 0
로그인하면 의견을 남길 수 있습니다.
아직 의견이 없습니다. 첫 의견을 남겨보세요.