www.webdeveloper.com
Results 1 to 2 of 2

Thread: Admin Panel Cookies - How would I do it?

  1. #1
    Join Date
    Jan 2012
    Posts
    16

    Admin Panel Cookies - How would I do it?

    Hi,

    I am creating an admin panel for my website. I have heard that it is possible to protect it in the following way:

    Admins (who should be able to access the admin panel) get a certain cookie.
    This cookie then allows them to get into the admin panel when they go to the panel directory.

    When anyone else goes to the panel directory, just gets taken back to the homepage, and doesn't see anything on the panel

    How would I do this?

    Thanks

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,389
    Typically this is done via PHP session-handling (e.g. starting with the session_start() function, and when the user logs in, add a setting in $_SESSION to indicate whether they are an admin user. Then on your admin-only pages, your logic would be something like:
    PHP Code:
    <?php // this must be the first line: no output of any kind before it
    session start();
    if(empty(
    $_SESSION['is_admin'])) {
      
    header("Location: http://www.example.com/default_landing_page.php");
      exit;
    }
    // rest of page...
    ?>
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles