config.php file tip

A lot of scripts will have a file called config.php or something similar that holds all the database connection info, site path and other bits and bobs like that. For years I’ve done something along the lines of, creating a copy of the config file, calling it configs and changing all the database information from my local machine to match the settings of my website, uploading all the files and then using FileZilla to change the name of configs to config. Easy to do but a bit time consuming and annoying and I thought there must be a better way and I came up with this:

if($_SERVER['SERVER_NAME'] == ‘localhost’){
// db settings for local machine
}
else{
//db settings for website
}

I also do the same with stats code, put it in a function and call the function where the stats code should be. This stops stats from being contaminated with hits from when I’m developing.

This entry was posted in Code. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>