Skip to main content
November 3, 2009
Question

How do I hide the admin button after someone has logged in as the administrator?

  • November 3, 2009
  • 2 replies
  • 594 views

Hi everyone,

I am using Dreamweaver CS3, my question is:

I have a login page that has check boxes at the bottom of the page that tell the database whether the user is an administrator or not.

After the owner of the site has logged in as the administrator I would like to be able to hide the administrator button, can this be done with PHP, if so how do I do it?

Thanks.

This topic has been closed for replies.

2 replies

Participant
November 3, 2009

Hello,

  Please try this:

<?php

   
function loggedin(){
       
return isset( $_SESSION['loggedin'] );
   
}

   
function require_login(){
       
if( !loggedin() ){
                header
( 'Location: /login.php?referrer='.$_SERVER['REQUEST_URI'] );
               
exit;
       
}
   
}

?>


Good Luck!

Sean Colicchio

Server Engineer

hosting.com

November 3, 2009

I would set a session variable once the person has logged in-

e.g

if($login)

{

     // your login code

     $_SESSION['admin'] = true;

}

in your html, wrap this PHP code around your button code

e.g.

<?php

if(!isset($_SESSION['admin']))

{

?>

<input type="submit" name="button" id="button" value="Admin" class="button"  />

<?php } // close the if statement ?>

if the $_SESSION['admin'] isn't set ( if(!isset ), the button will be displayed, if it is set (which you will have done after a successful login) the button won't be displayed.

hope this helps

Chris

November 3, 2009

Thankyou Chris, for getting back to me so quickly, I'll try out what you have suggested.

Thanks again.