Jump to content

[SOLVED] check if it is certain user and allow to go to page


rallokkcaz

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

?>

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.