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;
?>

Leave a Reply

Your email address will not be published. Required fields are marked *