php判断网站的状态码_使用PHP知道网站状态

php判断网站的状态码

When I create a website, I create an "app-top.php" file to place website settings in. It's just easier to place a bunch of variable is that file, include it at the top of pages, and know that you only need to change one file if a variable value needs to be changed. A good example of this is a business name change -- I don't want to have to do a search/replace on an entire directory (and risk causing errors) if I can just have a $BUSINESS_NAME that I can reference from my app-top.php file.

创建网站时,我会创建一个“ app-top.php”文件来放置网站设置。在该文件中放置一堆变量,将其包含在页面顶部,这很容易,并且您只需要如果需要更改变量值,则更改一个文件。 商业名称更改就是一个很好的例子-如果我只有一个可以从我的应用程序中引用的$ BUSINESS_NAME ,我就不需要在整个目录中进行搜索/替换(并且可能会导致错误) -top.php文件。

One setting is use is a $WEBSITE_IS_LIVE variable. Based on the value of this variable, I can tell if the website is up on the live server or my development server. Say the development server address is "[customer].dev.myutilitydomain.com" and the customer's hosting domain is "www.[customer].com". Here' how my PHP script can know if the site is live or not:

使用的一种设置是$ WEBSITE_IS_LIVE变量。 根据此变量的值,我可以判断该网站是在实时服务器上还是在我的开发服务器上。 假设开发服务器地址为“ [customer] .dev.myutilitydomain.com”,而客户的托管域为“ www。[customer] .com”。 这是我PHP脚本如何知道网站是否正常运行的方法:

$WEBSITE_IS_LIVE = !substr_count($_SERVER['HTTP_HOST'],'myutilitydomain.com');

What settings do I change depending on the value? Many, including:

我会根据值更改哪些设置? 许多,包括:

  • Database Username

    数据库用户名
  • Database Password

    数据库密码
  • Database Host

    数据库主机
  • Database Name

    数据库名称
  • Email Address (where to send live form email addresses to; if the site is in development, I want them going to me)

    电子邮件地址(将实时表单电子邮件地址发送到的地址;如果该网站正在开发中,我希望他们发送给我)

Those are just a few variables I manipulate using $WEBSITE_IS_LIVE. The best part about using the PHP code above is that I don't need to change the setting myself all the time -- using substr_count() automates the process.

这些只是我使用$ WEBSITE_IS_LIVE操纵的几个变量。 关于使用上面PHP代码的最好的部分是,我不需要一直更改自己的设置-使用substr_count()可自动执行该过程。

翻译自: https://davidwalsh.name/knowing-website-state-php

php判断网站的状态码

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值