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
I believe the best approach is to 'fake' a testing mode, which can be done by creating a file in your local environment.
When I used this approach I created an empty text file called testing.txt
and then used the following code:
if (file_exists('testing.txt')) {
// then we are local or on a test environment
} else {
// we are in production!
}
This approach is 100% compatible with any Operating System and you can use several test files in case you want a more granular approach (e.g. development.txt
, testing.txt
, staging.txt
, or production.txt
) in order to customise your deployment process.