...

View Full Version : session issue



bazz
01-09-2008, 11:38 PM
Hi,

I am new to php and sessions. The following code seems not to want to work.
I have started the session and I am merely trying to check if a value exists and if so, to output it. if not, to state that the value has not been set.

Hopefully the code is close but I ask for your assistance please.



<?php
session_start();
if(isset($_SESSION['sessionStartTime']))
$sessionStartTime = ". $_SESSION['sessionStartTime'];
echo "sessionStartTime = $sessionStartTime<br />";
else
echo "sessionStartime has not been defined";
?>





here's the error which I do not undertsand


PHP Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /var/www/vhosts/myDomain/httpdocs/index.php on line 4, referer



bazz

PappaJohn
01-10-2008, 12:02 AM
<?php
session_start();
if(isset($_SESSION['sessionStartTime']))
$sessionStartTime = $_SESSION['sessionStartTime'];
echo "sessionStartTime = $sessionStartTime<br />";
else
echo "sessionStartime has not been defined";
?>

shyam
01-10-2008, 12:04 AM
<?php
session_start();
if(isset($_SESSION['sessionStartTime']))
$sessionStartTime = ". $_SESSION['sessionStartTime'];
echo "sessionStartTime = $sessionStartTime<br />";
else
echo "sessionStartime has not been defined";
?>



there are 2 problems actually the first is the wrong quoting and the other is not enclosing multiple statements in {} for the if statement

something like this should solve ur problem

<?php
session_start();
if(isset($_SESSION['sessionStartTime'])) {
$sessionStartTime = $_SESSION['sessionStartTime'];
echo "sessionStartTime = $sessionStartTime<br />";
} else
echo "sessionStartime has not been defined";
?>

bazz
01-10-2008, 12:15 AM
Thank you both.

That's been a timely reminder, not to follow online tutorials just because they look the part.

bazz



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum