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

前端 未结 6 2092
伪装坚强ぢ
伪装坚强ぢ 2021-02-15 00:44

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:22

    Just in case this is useful to anybody, I made this function as the above answers didn't really do what I was looking for:

    function is_local() {
        if($_SERVER['HTTP_HOST'] == 'localhost'
            || substr($_SERVER['HTTP_HOST'],0,3) == '10.'
            || substr($_SERVER['HTTP_HOST'],0,7) == '192.168') return true;
        return false;
    }
    

提交回复
热议问题