session_start();
session_register("user_session");
session_register("cat_user_session");
The inspection whether user have login or not is by checking whether variable session is already exist or not, you can use session_is_registered() function.
Here is the example if the user who did not login then tries to access page 1 (page1.php program file).
In order to check this variable session, you have to make a program file so that it can be 'include' in every pages:
<?
//variable session check program
//check_first.php
session_start();
if(!session_is_registered(user_session)){
echo"You are not Login yet.
You are not allowed to access this page";
echo("<br><a href=user.form.php><<< Login >>></a>");
exit;
}
?>
Every pages of this website has their own user category. For example, page 1 (page1.php) and page 3 (page3.php) can be accessed by all of the user then page 2 (page2.php) can only accessed by super user.
<?
//page 1 is the same with page 3
//page1.php
include"check_first.php";
echo"Welcome in page 1 user: $user_session";
?>
<?
//page 2
//page2.php
include"check_first.php";
//check whether user is a super user
if($cat_user_session!="super user"){
echo"You are not allowed to access this page";
exit;
}
echo"Welcome in page 2 user: $user_session";
?>
The result is:
| Series this article: Session Variable: Introduction Session Variable: Session Application Session Variable: Simple Login Checking Tag: session, variable, login Category: PHP Basic Post : March 08th 2008 Read: 1,163 blog comments powered by Disqus |