Home Know Me Snaps Feedback
 
What is php sessions ?
 

PHP sessions are areas of a web server that we can store information about users on a web site.
We can use sessions to store information like.
Clients Username
Weather the user is login or not
or stor What you like.
We can also use sessions to track the user on your web site so as the user changes from one page to another the user will say loged in.

What are php sessions
  When A new session is assigned to a client they are given an unique string called a session id this string is stored in a cookie on the clients machine. This is what the clients web browser uses to access the session data. So if you think about it, If you have someone elses session id you can trick the server into thinking your loged in as someone else
by changing the session id in your cookies to their session id.
Basic Sessions Start
   session_start();
  Sessions are used like any other array well look at the code’s below.
  Creating a session vairable:
  session_start();
$_SESSION['session_name'] = "Hello";
  Useing the Session Variable
  session_start();
echo $_SESSION['session_name'];
  Session Variables can be used on any page of your sever aslong as you use session_start(); to tell the server your going to use Session variables.
  An example of A SESSION in action

On An earlyer Page the client visited theses sessions where set up (login page)
$_SESSION['user_id'] = 1; <---- user account as a number repsenting that user
$_SESSION['username'] = mofm; <---- thse users username
$_SESSION['email'] = "email@server.com";<----- Users Email
$_SESSION['logedin'] = True; <------ this is set to true is the user has logedin
  session_start();// Tells server To get ready For session information

if(SESSION['logedin'] == True) //If user is loged in change $username to the username stored in the sessions
{
$username = $_SESSION['username']." ";
}
else
{
$username = "Guest "; // if not logedin change $username to guest
}
echo "Welcome To the Site " .$username;
echo "<A HREF='mailto:" .$_SESSION['email']." >Your Email</A>";
 

This code can be improved and thir is a problem with it, If u understood anything from the tutorial you will be able to fix it

   
   
   
  PHP Table of Content
  Php sessions System
  Create a PHP contact form
  Comment System with php/mysql
  Admin Login and Delete Comment
  Simple file upload
  File Upload Function
  Connect with mysql database
 
   
 
 
       
   
© 2008, krishnakumar.com.np. All rights reserved
.