PHPEveryday.com PHP and Web Development Tutorial
What are you looking for?


Session Variable: Simple Login Checking


Session Variable Step By Step Tutorial - Part 3: From the user.form.php program at previous post, the program will check whether user's name and password is correct and registered in user.dat.php file or not. If not, the login will be denied. If it is correct, so the program will register the name and the password as variable session and the order is:
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).

session variable check login

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:

session variable

session variable


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,179 Bookmark and Share

blog comments powered by Disqus


Database Tutorial
  • Learn PHP MySQL
  • Learn PHP ADOdb
  • Learn PHP Data Object/PDO
  • Learn PHP XML
  • Learn PHP SimpleXML
Security Tutorial
  • Learn PHP Security
  • Learn HTTP Authentication
  • Learn PHPSecureSite
Framework Tutorial
  • Learn CodeIgniter
  • Learn Joomla
  • Learn Smarty
  • Learn Zend Framework
Template Tutorial
  • Learn Joomla Template
  • Learn WordPress Template
API Tutorial
  • Learn Facebook
JS Framework Tutorial
  • Learn MooTools
  • Learn JQuery
AJAX Tutorial
  • Learn AJAX in 10 Minutes
  • Learn AJAX Client Side
  • Learn AJAX PHP
  • Learn AJAX Remote Server
  • Learn AJAX Repetitive
  • Learn AJAX MySQL
  • Learn AJAX Grid
Web Services Tutorial
  • Learn Web Services NuSOAP
  • Learn Web Services WSDL
  • Learn Web Services WSDL Array
  • Learn Web Services .NET Grid
  • Learn Web Services WDDX
Package Post
  • Joomla Intro
  • Joomla Component
  • Joomla Module
  • Joomla MVC
  • Joomla MVC Backend
  • PostNuke Intro
  • Zend Framework Intro
  • Zend Framework Action
  • Zend Framework Database
  • Zend Framework Registry
  • Zend Framework Config
  • Zend Framework Login
  • Zend Framework Session
  • PHP Array Tips
  • PHP File Tips
  • PHP Email
  • PHP Ms Excel
  • PHP Pattern
  • PHP SMS
  • Flash Database
  • PHP Multitier
  • jQuery Introduction
  • jQuery Selectors
  • Portable Web Server
  • Web Mobile Intro
  • Drupal Installation
  • Drupal Configuration