eHow launches Android app: Get the best of eHow on the go.

How To

How to Start and Clear a Session in PHP

Member
By Mike
User-Submitted Article
(0 Ratings)

We here the term all the time called "cookie". In reference to the web a "cookie" is when a website stores information on a person's computer to be used at a later time. That later time could be 10 minutes or 30 days. A session is the same thing in essence except it is only valid while the user is on a website. PHP offers a very easy way to create and clear session information. Here is how it is done.

Difficulty: Easy
Instructions
  1. Step 1

    To start a new session in PHP we use the code:
    session_start();

    This creates a brand new session and a unique session identification number which can be obtained by using the built in function code:
    session_id();

  2. Step 2

    Once you have your session created you start adding values to your session by assigning the values what are called session variables. For example you can use:
    $_SESSION['firstname']='mike';

    Firstname is the session variable and 'mike' is its value. If you ever want to retrieve the value of firstname you would write this code:
    echo $_SESSION['firstname'];

  3. Step 3

    Now that you know how to start a session and assign variables within a session, you need to know how to clear a session. This is simple. You use the built in function session_destroy();
    This will clear all of the variables and their values within a session, but it does not however clear the session_id value. That will remain.

Post a Comment

Post a Comment
  • Have you done this? Click here to let us know.
I Did This

Related Ads

Computers
Alexia Petrakos,

Meet Alexia Petrakos eHow's Computers Expert.

Get Free Computers Newsletters

Copyright © 1999-2009 eHow, Inc. Use of this web site constitutes acceptance of the eHow Terms of Use and Privacy Policy.   en-US Portions of this page are modifications based on work created and shared by Google and used according to terms described in the Creative Commons 3.0 Attribution License.

eHow Computers
eHow_eHow Technology and Electronics