Skip to content

Instantly share code, notes, and snippets.

@cyberwani
Forked from troutacular/is_localhost
Created February 10, 2020 17:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cyberwani/1c39168585e62db083bc15027a29b2ec to your computer and use it in GitHub Desktop.
Save cyberwani/1c39168585e62db083bc15027a29b2ec 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment