我试过你下面的代码,并按预期工作。
<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代码
<?php
echo file_get_contents('https://' . $_GET['url']);
?>
其装载谷歌地图没有任何错误。
编辑
在下面评论的反应是可能的最佳解决方案。
您正在寻找的设置是allow_url_fopen
。
在php.ini文件中设置allow_url_fopen = On
。
你有两种方法可以在不改变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);
感谢您的答案,但它不是我的目的,googleMapAdress =影射=>从google.map一个地址,如何得到任何外部网页,并在DIV加载元素完全与ajax? – geeking
当想要使用https协议获取外部页面时,我看到这个警告:'警告: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第2行' – geeking
请看我更新的答案。 –