Monday, 20 May 2013

use of session in php


Use Of Session in PHP:

    A session is a way to store information (in the form of variables) to be used across multiple pages. Unlike a cookie, specific variable information is not stored on the users computer. It is also unlike other variables in the sense that we are not passing them individually to each new page, but instead retrieving them from the session we open at beginning of each page.

    USE OF session_start()

    Session_start() is used in PHP to initiate a session on each PHP page. It must be the first thing sent to the browser, or it won't work properly,so it usually best place to use in php script at the top.

    Example
    <?php // this starts the session session_start(); ?>


    Use Of session variable($_SESSION)

    A session variable is used to store information at server side and represented by $_SESSION.
    Example
    <?php // this starts the session session_start(); // this sets variables in the session $_SESSION['color']='red'; $_SESSION['size']='small'; $_SESSION['shape']='round';

    ?>

    Use Of session_unset()

    Session_unset () is used to remove all variables in a session.
    session_unset() is used to remove all session variables
    Example
    <?php //start session environment session_start(); //this would remove all session variables session_unset();

    ?>


    Use Of unset()

    unset () is used to delete value of particular session variable.
    Example
    <?php //delete the value of session variable sid unset($_SESSION['sid']);

    ?>


    Use Of session_destroy()

    session_destroy() is used to destroy complete session environment.
    Example
    <?php //destroy the session session_destroy();

    ?>

No comments:

Post a Comment