steviez Posted February 15, 2007 Share Posted February 15, 2007 Hi, I would like to make my site able to go offline (Down for maintenence) and not allow access to any pages on the site untill it is back up. I am wanting like a button to activate this setting in my admin section. Is this possable? Thanks Quote Link to comment Share on other sites More sharing options...
trq Posted February 15, 2007 Share Posted February 15, 2007 Yes. its possible. Simply put soemthing like... <?php include("config.php"); if (DOWN) { header("location :down.html"); } ?> In the top of each page. In config.php you would need something like... <?php // set to FALSE for site to go live. define("DOWN",TRUE); ?> Quote Link to comment Share on other sites More sharing options...
steviez Posted February 15, 2007 Author Share Posted February 15, 2007 i cant eget it to work, this would be great if it works Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted February 15, 2007 Share Posted February 15, 2007 The method proposed by thorpe would work if implemented correctly. What exactly are you having trouble with? Quote Link to comment Share on other sites More sharing options...
steviez Posted February 15, 2007 Author Share Posted February 15, 2007 it works, but when set to false in config it still goes to down.html Quote Link to comment Share on other sites More sharing options...
steviez Posted February 15, 2007 Author Share Posted February 15, 2007 I have got this working now, is there a way to only give my IP access? Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted February 15, 2007 Share Posted February 15, 2007 If your IP address changes periodically that won't be very convenient. Why not set up a debug cookie? Quote Link to comment Share on other sites More sharing options...
steviez Posted February 15, 2007 Author Share Posted February 15, 2007 excuse my lack of knowlage, how is this done? Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted February 15, 2007 Share Posted February 15, 2007 BakeDebugCookie.php <?php // BakeDebugCookie.php // Create a debugging cookie that enables developers to enter the // site when it's down, or areas of the site not open to the general // public. $user = 'username'; $pass = 'password'; if(count($_POST)){ // Form submitted $gooduser = isset($_POST['user']) && !strcmp($_POST['user'], $user); $goodpass = isset($_POST['pass']) && !strcmp($_POST['pass'], $pass); if($gooduser && $goodpass){ setcookie('DebugCookie', 'On', time() + 60 * 60 * 24 * 14); $form = "Cookie set"; }else{ $form = "Try again, suckafoo."; } }else{ // Display form $form = <<<FORM <form action="" method="post"> User: <input type="text" name="user" value="" /> Password: <input type="password" name="pass" value="" /> <input type="submit" value="Submit" /> </form> FORM; } echo $form; ?> EatDebugCookie.php <?php // EatDebugCookie.php // Delete the debug cookie setcookie('DebugCookie', 'On', time()); ?> MyDebug.php <?php // MyDebug.php // Define simple debugging stuff // isDebug // RETURN: true if debug is on, false if off function isDebug(){ return isset($_COOKIE['DebugCookie']) && $_COOKIE['DebugCookie'] == 'On'; } ?> Then in your scripts, you just check if the site is down. If the site is down and the user doesn't have the debug cookie ( !isDebug() ), they get redirected. Just make sure you write your logic in a way that if the site isn't down they still don't get redirected. Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted February 15, 2007 Share Posted February 15, 2007 Just to throw one more wrench into things, I wouldn't really consider it secure or good practice to have the user, password, and cookie name hard coded like that. A much better approach would be to define those elsewhere in a small .php file with 3 define statements. Then you can create a cron job on the server that runs once a month or whatever and changes them to random values. That way if you lay someone off within your company, you can run the script on the server and you have new debugging information. You set it up to run automatically just in case an outside source happens to discover them, that would (hopefully) limit the window of time they could use it to do anything to your system. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.