php 包含到外部 url
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9196228/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
php include to external url
提问by Phil
I am currently trying to use the php function 'include' to include an external url. This is so that whenever the webpage is updated it will automatically update mine. The trouble I'm having however is that I keep getting an error saying the following...
我目前正在尝试使用 php 函数“include”来包含外部 url。这样每当网页更新时,它就会自动更新我的。然而,我遇到的麻烦是我不断收到错误消息,说明以下内容......
Warning: require() [function.require]: http:// wrapper is disabled in the server configuration by allow_url_include=0 in C:\wamp\www\starterpack\starterpack2\header.php on line 48
警告:require() [function.require]: http:// wrapper is disabled in the server configuration by allow_url_include=0 in C:\wamp\www\starterpack\starterpack2\header.php on line 48
I have tried to find a way to fix this error or find a way around it but cannot find one. Does anyone have any ideas?
我试图找到一种方法来修复此错误或找到解决方法,但找不到。有没有人有任何想法?
P.S I am building the site using wampserver, could permissions of the wampserver be causing this error?
PS 我正在使用 wampserver 构建站点,wampserver 的权限是否会导致此错误?
回答by diolemo
You would be better using echo file_get_contents($url)
as the include statement could execute any PHP code returned by the other site.
您最好使用,echo file_get_contents($url)
因为 include 语句可以执行其他站点返回的任何 PHP 代码。
回答by Barry Chapman
Look at your php.ini and make sure allow_url_include is set to 1. Restart HTTPD, done.
查看您的 php.ini 并确保将 allow_url_include 设置为 1。重新启动 HTTPD,完成。
回答by Nicholas Valbusa
function getter($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
echo getter('http://yourdomain.com/externalfile.php');
And you're done :)
你完成了:)
回答by Wayne Nort
This will load an external website and also gives external links an absolute website link address
这将加载一个外部网站,并为外部链接提供一个绝对的网站链接地址
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.your_external_website.com");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result = curl_exec($ch);
curl_close($ch);
$result = preg_replace("#(<\s*a\s+[^>]*href\s*=\s*[\"'])(?!http)([^\"'>]+)([\"'>]+)#",'http://www.your_external_website.com/', $result);
echo $result
回答by Prashanth
Look at your php.ini and make sure allow_url_include is set to 1
查看您的 php.ini 并确保将 allow_url_include 设置为 1
Otherwise use following ...
否则使用以下...
function getter($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
$data = curl_exec($ch);
curl_close($ch);
return $data;}
echo getter('http://yourdomain.com/externalfile.php');