Skip to content

Instantly share code, notes, and snippets.

@ron4stoppable
Created September 16, 2016 11:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ron4stoppable/d994d520c9a5141e469897a6cef9704d to your computer and use it in GitHub Desktop.
Save ron4stoppable/d994d520c9a5141e469897a6cef9704d to your computer and use it in GitHub Desktop.
Detect and connect to db server with proper configuration. The code check if the web app is hosted at localhost or a web server and load proper db configuration.
$local = array(
'127.0.0.1',
'::1'
); // localhost
if(!in_array($_SERVER['REMOTE_ADDR'], $local)){
require_once('connection-db.php'); // db connection details for server
}
else{
require_once('db-connect-local.php'); // db connection details for localhost
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment