0
<?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.

3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by cwarn23
0

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();


?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.