Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to use session in php. ?

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 261
    Comment on it

    Firstly let us know what is session ?

    Session variables hold information about one single user, and provide to all pages information in one application.
    So, session basicallu store informatiom in a variable and provine in multiple page for a single user How to start a session

    session_start();

    Note:- session starts Before any HTML tags.

    You can see below example of session in php.

    <?php
    
    // fix session variables
    $_SESSION["favcity"] = "Landon";
    $_SESSION["favcountry"] = "UK";
    // echo  session variables  
    echo "Session variables will come". ".<br>";
    
    //now here call session variables that were set on previous page
    echo "Favorite city is " . $_SESSION["favcity"] . ".<br>";
    echo "Favorite country is " . $_SESSION["favcountry"] . ".";
    
    ?>
    

    Output will come:
    Session variables will come.
    Favorite city is Landon.
    Favorite country is UK.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: