Skip to content

Instantly share code, notes, and snippets.

@tinshade
Created October 16, 2020 14:00
Show Gist options
  • Save tinshade/5949fcbc0528346d8044232526dd23d3 to your computer and use it in GitHub Desktop.
Save tinshade/5949fcbc0528346d8044232526dd23d3 to your computer and use it in GitHub Desktop.
PHP code to check if you are on LocalHost or On the Server. Mostly useful to switch between local and server DB without changing the config file too often.
<?php
$whitelist = array('127.0.0.1','::1');
if(!in_array($_SERVER['REMOTE_ADDR'], $whitelist)){
echo 'Not Whitelisted<br/>'.$_SERVER['REMOTE_ADDR'];
}else{
echo 'Whitelisted<br/>'.$_SERVER['REMOTE_ADDR'];
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment