phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


Session Variable: Session Application

Tag: session, variable, login   Category: PHP Basic
post: 08 Mar 2008 read: 272


Session Variable Step By Step Tutorial - Part 2: Session is usually used for the security aplications and e-commerce (online shopping). A website user will be checked first whether he is allowed to access the site or not. For example, the user who already gets the permission of 'user' identification. Not all of the user can access the whole website pages itself because there are some of the pages can only be accessed by 'super user'.

In making this application, first, you have to make a file named 'user.dat.php' which contains of three field datas. There are name, password, and user identification data. You can use md5() function in order to make password (string 32 character).


<?
,dian,superuser,f97de4a9986d216a6e0fea62b0450da9,
ryan,user,10c7ccc7a4f0aff03c915c485565b9da,
brian,user,cbd44f8b5b48a51f7dab98abcdf45d4e,
?>

Next, you will see a form where the visitor must have to fill the name and password.


<?
//form login
//user.form.php

if($submit){
  $password = md5("$password");
  $fh=fopen("user.dat.php","r");
  $str= fread($fh,1024*40);
  $str01 = explode(",",$str);
  $i=1;
  $u=0;
  while($str01){
    if($name==$str01[$i] && $password==$str01[$i+2]){
      session_start();
     $user_session = "$str01[$i]";
     $cus = $i + 1;
     $cat_user_session = "$str01[$cus]";
     session_register("user_session");
    session_register("cat_user_session");
    echo "Welcome User: $str01[$i]";
    echo ("<p><ol><li><a href=page1.php>Look 
page 1 >>></a></li>");
    echo ("	  <li><a href=page2.php>Look 
page 2 >>></a></li>");
    echo ("   <li><a href=page3.php>Look page 
3 >>></a></li></ol>");
    $u = 1;
    break;
  }
  $i += 3;
  if($i>(count($str01)+3)){
    break;
  }
}

  if($u != 1){
    echo("<br>You are not user");
  }
}else{

echo("<form method=post action=$PHP_SELF>");
echo("<table>");
echo("<tr>");
echo("<td>Welcome");
echo("</td>");
echo("</tr>");
echo("<tr>");
echo("<td>Name        <input 
	type=text name=name size=30>");
echo("</td>");
echo("</tr>");
echo("<tr>");
echo("	<td>Password  <input 
type=password name=password 
	size=30>");
echo("</td>");
echo("</tr>");
echo("</tr>");
echo("<tr>");
echo("<td align=right><input type=submit 
name=submit value=Process size=30>");
echo("</td>");
echo("</tr>");
echo("</table>");
echo("</form>");
}
?>

Then the result will be:

session application form


Series this article:
Session Variable: Introduction
Session Variable: Session Application
Session Variable: Simple Login Checking

| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Chart: How to Build Cool Animation Real Time Chart
Joomla: Fast Road to Understand Component Programming
Email: Send Attachement Mail
mod_rewrite - Part 1: create your "fantasy" URL

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


615
posting