Jump to content

Recommended Posts

you should perhaps look at storing a user level with each user adn this turorial is excellent for developing an access level system.

 

http://www.phpfreaks.com/tutorials/151/1.php

 

dont' be put off - read it a couple of times and you will see that its not anywhere near as difficult as you may think initially.

 

(the last page of the turial will show you how you can use it to allow/deny access to pages based on your login.)

At the top of every page (before any php or html code) that you only want the admin user to access put include("adminheader.php");

then the files needed are below. should work fine....ive used it in projects.goodluck!

 

 

adminheader.php------------------------------------------------------------------------

<?php

session_start(); // start session

if(!isset($_SESSION['username'] or $_SESSION['username']=='admin')) //check to see if the username is set in the session and if it ='admin'

{

include("logout.php"); //if its not set or wron user call logout.php

exit(); //exit

}

 

?>

----------------------------------------------------------------------------------------

logout.php-----------------------------------------------------------------------------

<?php

session_start();

session_unset();  //unset any session variable set

session_destroy(); //end the session

header("location:index.php"); //send them back to the login page or a home page

?>

----------------------------------------------------------------------------------------

spotted an error in my reply....fixed below in the red...sorry

 

 

 

At the top of every page (before any php or html code) that you only want the admin user to access put include("adminheader.php");

then the files needed are below. should work fine....ive used it in projects.goodluck!

 

 

adminheader.php------------------------------------------------------------------------

<?php

session_start(); // start session

if(!isset($_SESSION['username'] or $_SESSION['username']!='admin')) //check to see if the username is set in the session and if it ='admin'

{

include("logout.php"); //if its not set or wron user call logout.php

exit(); //exit

}

 

?>

----------------------------------------------------------------------------------------

logout.php-----------------------------------------------------------------------------

<?php

session_start();

session_unset();  //unset any session variable set

session_destroy(); //end the session

header("location:index.php"); //send them back to the login page or a home page

?>

----------------------------------------------------------------------------------------

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.