How to check if the php script is running on a local server?

前端 未结 6 1261
傲寒
傲寒 2021-02-15 00:59

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 ap

6条回答
  •  遇见更好的自我
    2021-02-15 01:14

    You should automate deployment

    This is not directly the answer to your question, but in my opinion the better way. In an automated deployment process, setting a variable like $local = true, like other configuration values (for example your db-connection), would be no manual, error prone, task.

    Checking for 'localness' is in my opinion the wrong way: you dont want to show your logs to every local visitor (a Proxy may be one), but only when deployed in a testing environment.

    A popular tool for automated deployment is Capistrano, there should be PHP-Centric tools too.

提交回复
热议问题