Check session variables exists – PHP

Before using a session variable ,we must check if that variable exists in $_SESSION array and that can be done using the function .

Example

<?php
session_start();
if(isset($_SESSION[‘phpcodez_views’]))
$_SESSION[‘phpcodez_views’] = $_SESSION[‘phpcodez_views’]+ 1;
else
$_SESSION[‘phpcodez_views’] = 1;
?>

session php

Session variables are used to store values that are required across multiple web pages .

A website can not remember anything about the users those who have already visited the site since the HTTP request does not have state . But at time , it is necessary to remember some details(eg should understand if a user is logged in or not ) . In such case we can use session that enable the website to store the information for later use .