Thursday, November 6, 2014

How to setting PHP Sessions

Firstly   type this code and save set.php


<?php
session_start();
$_SESSION['username']='faridul';
?>

Secondly type this code and save view.php:

<?php
    session_start();
   
    if(isset($_SESSION['username'])){
        $seevariavle= $_SESSION['username'];
        echo 'Welcome,' .$seevariavle;
   
    }
    else{
        echo "Please log in.";
   
    }
?>

 Result: browsers show ----Welcome faridul.

Thirdly type this code and save unset.php :

<?php
    session_start();   
    unset($_SESSION['username']);
?>

You see result such step: 1.visit view.php then visit unset.php.
finally visit view.php see result "Please log in"

No comments:

Post a Comment