954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

session error

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

davy_yg
Posting Whiz
377 posts since May 2011
Reputation Points: 10
Solved Threads: 0
 

maybe
if($_SESSION['LoggeIn'] .. instead of if(Session...

didier_m
Newbie Poster
20 posts since Aug 2010
Reputation Points: 10
Solved Threads: 2
 
maybe if($_SESSION['LoggeIn'] .. 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();


?>
cwarn23
Occupation: Genius
Team Colleague
3,033 posts since Sep 2007
Reputation Points: 413
Solved Threads: 259
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: