Backend Development

PHP Session is NULL

Submitted by Venipa, , Thread ID: 21822

Thread Closed

RE: PHP Session is NULL

Burned Designs
Web Developer/Designer
Prime
Level:
0
Reputation:
5
Posts:
115
Likes:
9
Credits:
484
14-06-2016, 04:47 PM
#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: 1 Guest(s)