Jump to content

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


rallokkcaz

Recommended Posts

if wanna make it so if the user "admin"

can only view a page without the whole system of 1s and 2s in the data base

would the code be something like:



if (isset($_session['username'] = 'admin'))
{

} else {

}

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

?>

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

Link to comment
Share on other sites

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

?>

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

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.