如何检查PHP脚本在本地服务器上运行? [英] How to check if the php script is running on a local server?

查看:346
本文介绍了如何检查PHP脚本在本地服务器上运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能来检查网站(PHP)在本地或托管的服务器上运行?
我想,如果网站在本地运行,使一些日志,我不希望这些出现在网站上的在线..
我可以设置一个变量 $本地= 1; ,但我不得不改变上传之前..反正有自动完​​成这一任务。

Is it possible to check if the website (php) is running locally or on a hosted server? I want to enable some logs if the website is running locally and I don't want these to appear on the site online.. I can set a variable $local=1; but I'll have to change that before uploading.. is there anyway to automate this task?

本地服务器:WampServer 2.0 /阿帕奇
Web服务器:Apache的

Local Server : WampServer 2.0 / Apache WebServer: Apache

推荐答案

检查 $ _ SERVER ['REMOTE_ADDR'] ==127.0.0.1。这如果在本地运行才会是真实的。请注意,这意味着本地的服务器上。所以,如果你有这使得请求PHP页面的服务器上运行任何脚本,他们会满足这个条件了。

Check $_SERVER['REMOTE_ADDR']=='127.0.0.1'. This will only be true if running locally. Be aware that this means local to the server as well. So if you have any scripts running on the server which make requests to your PHP pages, they will satisfy this condition too.

这篇关于如何检查PHP脚本在本地服务器上运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆