Jump to content

is this possable?


steviez

Recommended Posts

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);

?>

Link to comment
Share on other sites

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.  :D

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.