View Single Post
Old 12-17-2012, 01:34 AM   PM User | #1
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
Switch between local and live

I believe that many people will comment and uncomment blocks (or individual lines) of code when switching between local and live running of their pages. This can be a pain. I use the following code and just change a value from true to false when moving to the remote/live site:
PHP Code:
<?php
if (!defined('LOCAL')) {
    
define('LOCAL'true);      // set this to true or false
}
if (!
defined('DB_USER')) {
    if (
LOCAL) {
        
DEFINE('DB_USER''Andrew');
        
DEFINE('DB_PASSWORD''Password1');
        
DEFINE('DB_HOST''localhost');
        
DEFINE('DB_NAME''AndyDB');
        
DEFINE('EMAIL''andy@somemail.com'); 
        
DEFINE('BASE_URL''http://localhost:80/AndysProject/');
    } else {
        
DEFINE('DB_USER''user2');
        
DEFINE('DB_PASSWORD''Password2');
        
DEFINE('DB_HOST''www.some.com');
        
DEFINE('DB_NAME''db2');
        
DEFINE('EMAIL''host@someother.com'); 
        
DEFINE('BASE_URL''http://andyshost.com/');
    }
}
?>
I store this in a config.php file that is included in relevant pages.
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS

Last edited by AndrewGSW; 12-17-2012 at 01:37 AM..
AndrewGSW is offline   Reply With Quote