我已经在下面的代码中尝试过你,它的工作方式符合预期。
<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');
curl 的快速参考链接如下。
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);