从本地主机以外的其他地址访问 Symfony/web/config.php?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6383223/
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
Access Symfony/web/config.php from other address than localhost?
提问by wowpatrick
I'm currently testing different PHP frameworks to see witch on my going to use for my next project. I just installed Symfony2 on my web server. When trying to access the Symfony/web/config.php
file, Symfony blocks this file from being edited by any other than localhost. Of cures there is no gui on my server, so a visual config is quite usless without a browser.
我目前正在测试不同的 PHP 框架,以了解我将用于下一个项目的情况。我刚刚在我的网络服务器上安装了 Symfony2。当尝试访问该Symfony/web/config.php
文件时,Symfony 会阻止该文件被本地主机以外的任何人编辑。当然,我的服务器上没有 gui,因此如果没有浏览器,可视化配置就毫无用处。
Is there a way to call access the Symfony/web/config.php
file from any other address than loclhost?
有没有办法Symfony/web/config.php
从 loclhost 以外的任何其他地址调用访问文件?
回答by hakre
You can add your own host to that configuration so you can open it with your browser.
您可以将自己的主机添加到该配置中,以便您可以使用浏览器打开它。
To do so, add your host (that is your public WAN IP, e.g. you can google it) into the config.php
file. It's the array of hostnames on top, see the 'my very own ip'example entry:
为此,请将您的主机(即您的公共 WAN IP,例如您可以 google)添加到config.php
文件中。这是顶部的主机名数组,请参阅“我自己的 ip”示例条目:
if (!in_array(@$_SERVER['REMOTE_ADDR'], array(
'127.0.0.1',
'::1',
'my very own ip',
))) {
header('HTTP/1.0 403 Forbidden');
die('This script is only accessible from localhost.');
}
You should then be able to access the script on your server.
然后,您应该能够访问服务器上的脚本。
回答by tom.tomsen
If you are not sure from which ip you are connecting, use
如果您不确定要从哪个 IP 连接,请使用
var_dump($_SERVER['REMOTE_ADDR'])
var_dump($_SERVER['REMOTE_ADDR'])