<?php

session_start(); 


 // makes an array 
 $colors=array('red', 'yellow', 'blue'); 
 // adds it to our session 
 $_SESSION['color']=$colors; 
 $_SESSION['size']='small'; 
 $_SESSION['shape']='round';
 $_SESSION['diameter']='10cm';
   
 print "Done";

 function fnCheckSession(){
 
 if (Session["LoggedIn"] !=null)
 		echo "Session variable exist.";
	else	
 		echo "Session variable does not exist.";
 } 

fnCheckSession();


?>

I have the following error appears:

Parse error: syntax error, unexpected '[' in C:\xampp\htdocs\php_exercise\exercise2_2.php on line 18

line 18 is : if (Session["LoggedIn"] !=null)

What might be wrong?

Thanks.

Recommended Answers

maybe
if($_SESSION .. instead of if(Session...

Jump to Post

All 2 Replies

maybe
if($_SESSION .. instead of if(Session...

maybe
if($_SESSION .. instead of if(Session...

Indeed and he also forgot to use upper case null (NULL) along with the strictly not equal to match only the NULL although in some server setup's this is not necessary. So the corrected code will be as follows:

<?php

session_start(); 


 // makes an array 
 $colors=array('red', 'yellow', 'blue'); 
 // adds it to our session 
 $_SESSION['color']=$colors; 
 $_SESSION['size']='small'; 
 $_SESSION['shape']='round';
 $_SESSION['diameter']='10cm';
   
 print "Done";

 function fnCheckSession(){
 
 if ($_SESSION['LoggedIn'] !==NULL)
 		echo "Session variable exist.";
	else	
 		echo "Session variable does not exist.";
 } 

fnCheckSession();


?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.