Backend Development

PHP Session is NULL

Submitted by Venipa, , Thread ID: 21822

Thread Closed

RE: PHP Session is NULL

#2
Have you tried if(empty()) ?

PHP Code:
<?php
  
if(empty($_SESSION['test'])){
   
session_start();
   
$_SESSION['test'] = "Session has started";
   
print_r($_SESSION['test']);
   echo 
"<a href='destroy.php'>Destroy</a>";
  }else{
   die(
"Session is not started");
 }
  
?>

Or if you still prefer using !isset

PHP Code:
<?php
  
if(!isset($_SESSION['test'])){
   
session_start();
   
$_SESSION['test'] = "Session has started";
   
print_r($_SESSION['test']);
   echo 
"<a href='destroy.php'>Destroy</a>";
  }else{
   die(
"Session is not started");
 }
  
?>


Destroy.php

PHP Code:
<?php
  session_destroy
();
  
header("refresh:0; url=index.php");
?>
[Image: SIG.PNG]

Users browsing this thread: 2 Guest(s)