Skip to content

Instantly share code, notes, and snippets.

@troutacular
Created May 30, 2015 00:02
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save troutacular/076f4c8b03a47d7e4b37 to your computer and use it in GitHub Desktop.
Save troutacular/076f4c8b03a47d7e4b37 to your computer and use it in GitHub Desktop.
PHP - Check if localhost
// Check if we are in a local environment
function is_localhost() {
// set the array for testing the local environment
$whitelist = array( '127.0.0.1', '::1' );
// check if the server is in the array
if ( in_array( $_SERVER['REMOTE_ADDR'], $whitelist ) ) {
// this is a local environment
return true;
}
}
// end
@atanemani
Copy link

This is useful, thanks.

@w3spi5
Copy link

w3spi5 commented Sep 18, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment