2013-01-18 3 views
1

내가 DIV 요소 의 도메인을 URL를로드 할 내가이 문제가 : 주소를로드하지 않는 HTTP 프로토콜 예를 들어 'google.com'에 대한 도메인을로드하는 경우구글지도 아약스와 PHP

  • 을 이미지는 올바르게 표시되지만 페이지를로드하십시오!
  • https 프로토콜을 사용하여 Google지도를로드하면 경고가 표시되고 절대로 작동하지 않습니다! 여기

내 코드입니다 :

load.php

<html> 
<head> 
    <title></title> 
    <script type="text/javascript" src='jqurey.js'></script> 
</head> 
<body> 
    <div></div> 
    <script type="text/javascript"> 
     $(function(){ 
      $('div').load('/x-request.php?url=googleMapAdress'); 
     }); 
    </script> 
</body> 
</html> 

X-request.php

<?php 
    echo file_get_contents('https://' . $_GET['url']); 
?> 

참고 : 사용하지 않을 iframe 크기 : &

내 코드에는 아약스 코드가 있어야합니다!

해결 방법은 무엇입니까 ??

// 자세한 설명

div 요소에서 외부 페이지를 가져 와서 완전히로드하는 방법은 무엇입니까? 이것은 수단 => href, src이고 모든 링크가 참으로 작동합니다.

답변

1

아래 코드를 사용하여 예상대로 작동하도록 노력했습니다. 오류없이

<?php 
    echo file_get_contents('https://' . $_GET['url']); 
?>

<html> 
<head> 
    <title></title> 
    <script type="text/javascript" src='js/jquery.js'></script> 
</head> 
<body> 
    <div></div> 
    <script type="text/javascript"> 
     $(function(){ 
      $('div').load('x-request.php?url=maps.google.com'); 
     }); 
    </script> 
</body> 
</html>

PHP 코드는 그것의 로딩 구글지도.

다음 주석의 응답에서 편집

는 가능한 최고의 솔루션입니다.

찾고 계신 설정은 allow_url_fopen입니다.

세트 allow_url_fopen = On php.ini 파일에 있습니다.

php.ini를 변경하지 않고 두 가지 방법으로 접근 할 수 있습니다. 하나는 fsockopen이고 다른 하나는 cURL입니다.

컬 예

function get_content($URL) 
{ 
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_URL, $URL); 
    $data = curl_exec($ch); 
    curl_close($ch); 
    return $data; 
} 

echo get_content('http://example.com');

빠른 참조 링크 넘기기 위해 다음과 같다.

http://www.kanersan.com/blog.php?blogId=45

http://www.tomjepson.co.uk/enabling-curl-in-php-php-ini-wamp-xamp-ubuntu/

<php 
$ch = curl_init();// set url 
curl_setopt($ch, CURLOPT_URL, $_GET['url']); 
//return the as a string 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt($ch,CURLOPT_BINARYTRANSFER, true); 
// echo output string 
$output = curl_exec($ch); 
$url = $_GET['url']; 


$path = 'http://'.$url.'/'; 
$search = '#url\((?!\s*[\'"]?(?:https?:)?//)\s*([\'"])?#'; 
$replace = "url($1{$path}"; 
$output = preg_replace($search, $replace, $output); 

echo $output; 

// close curl resource to free up system resources 
curl_close($ch);
+0

답변을 주셔서 감사하지만 외부 페이지를 얻을 사업부에서로드 어떻게 내 목적, googleMapAdress = 풍자 => google.map에서 주소, 아니다 요소가 완전히 아약스인가? – geeking

+0

https 프로토콜을 사용하여 외부 페이지를 가져 오려면 다음 경고 메시지가 표시됩니다. 'Warning : file_get_contents() [function.file-get-contents] : 래퍼'https '를 찾을 수 없습니다. 구성된 PHP? 2 행의 C : \ xampp \ htdocs \ x-request.php 경고 : file_get_contents (https://google.com) [function.file-get-contents] : 스트림 열기 실패 : C : \의 잘못된 인수 xampp \ htdocs \ x-request.php on line 2' – geeking

+0

내 대답을 참조하십시오. –