Forum Moderators: coopster

Message Too Old, No Replies

session

         

magua100

8:39 pm on Aug 22, 2005 (gmt 0)

10+ Year Member



I am trying to test the session varilble to test condition. Here is my code.

<?
if (isset($_SESSION['s_admin'])) == 1 {
echo "You are currently logged in as ".$_SESSION['s_admin'].", &nbsp;&nbsp;<a href=logout.php>Log-Out</a><br><br>";
}else{
echo "You are not logged in you log in <a href='login.php'>here</a> or register <a href='register.php'>here</a>.";
echo $_SESSION['s_username'];
print "<META HTTP-EQUIV='Refresh' content='0;URL=login.php'>";
}
if $_SESSION['s_admin'] == 1 {
echo "ok";
}
?>

I need to test weather session varible = 1 for just this one page. however i get the "unexpeded equal to error.

Any

sned

10:04 pm on Aug 22, 2005 (gmt 0)

10+ Year Member



Hi! and welcome to WebmasterWorld ....

a couple of things that I see:

if (isset($_SESSION['s_admin'])) == 1

I'm not sure why you need the == 1 here, but if thats what you want to do, try the )'s in a different spot:
if(isset($_SESSION['s_admin']) == 1)

if $_SESSION['s_admin'] == 1

This needs to have parens around it as well:
if($_SESSION['s_admin'] == 1)

-sned

mcibor

10:08 pm on Aug 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You don't want to check isset === 1 - isset returns true, not 1.
Moreover 3 = is too many in your case. Correct the if to:

if (isset($_SESSION['s_admin'])) {//just to see if it's set
echo "You are currently logged in as ".$_SESSION['s_admin'].", &nbsp;&nbsp;<a href=logout.php>Log-Out</a><br><br>";
}else{
echo "You are not logged in you log in <a href='login.php'>here</a> or register <a href='register.php'>here</a>.";
echo $_SESSION['s_username'];
print "<META HTTP-EQUIV='Refresh' content='0;URL=login.php'>";
}
?>

or in your way:
if((isset($_SESSION['s_admin'])) == true) {

Michal Cibor