Tuesday, November 27, 2018

What is session in php? how can use the php session?

What is Session:- 
A php Session variable  is stored the single user information and are available all the page in the application.

A PHP session solves this problem by allowing you to store single user informations on the server at a time.session information is the temporary store on the server,you are left the site then will be deleted.

Session work on a unique ID because they are stored single unique value on the server. 

Starting a php session-
                                                   <?php
                                                                start_session(); // session is start
                                                       ?>

A simple Example describes below for using php session on a  page-
session.php

<?php
  session_start();
//session initialization 
  $_SESSION['view'] = 'rajendra'; // storing session (value rajendra) * view is session name this is optional if you want then change the name
  
?>
<?php
    echo "welcome " . $_SESSION['view'] . "<br/>"; 
// print the session value welcome  rajendra
?>


<?php
    if(isset($_SESSION['view']))
    {
        echo "Session is set..."; // session have a value then session is set 
    }
    else
    {
        echo "Session not set...";
    }
?>

<?php
    unset($_SESSION['view']); // unset the session value because session is logout
    session_destroy(); // delete all information of the session called session_destroy
    echo "session destroy...";
?>

Related Posts:

  • Welcome To My Blog                                                               … Read More
  • OOP PHP Login Tutorial   What is a PHP Secure Login System with Registration? Many applications need to register and authenticate users. Some users have developed their own packages for this purpose, others have used existing p… Read More
  • History Of PHP The History Of Php  PHP is an "HTML-embedded scripting language" primarily used for dynamic Web applications. The first part of this definition means that PHP code can be interspersed with HTML, making it sim… Read More
  • Create a MySQL Database Using MySQLi and PDO The following examples create a database named "myDB": <?php $servername = "localhost"; $username = "username"; $password = "password"; // Create connection$conn = new mysqli($servername, $us… Read More
  • PHP Case Sensitivity PHP Case Sensitivity In PHP, all keywords (e.g. if, else, while, echo, etc.), classes, functions, and user-defined functions are NOT case-sensitive. In the example below, all three echo statements below are legal (and … Read More

0 comments:

Post a Comment