Jump to content

[SOLVED] I have a small problem to do with sessions...


forumnz

Recommended Posts

I have a user login/logout section. On another section I have a part where the user doesnt need to be logged in... but i want a piece of text up the top to read "Login" when thay arent, and "Logout" when they are.

So far I just have "Login"

This is the small piece of PHP that should do it for me...

[code]<?php
if (!$_SESSION['username'])
{
echo('Log In');
} else
{
echo('Log Out');
}
?>[/code]

Thanks.
make sure you are using session_start(); at the very top of your page, no spaces... nothing between it...

also, remove your brackets in your echo, that is not good coding practise... and i would use isset in the if statement...

[code=php:0]
if(!isset($_SESSION['username'])){
echo "Log In";
}else{
echo "Log Out";
}
[/code]

:)
[quote author=ProjectFear link=topic=120588.msg494852#msg494852 date=1167689975]
make sure you are using session_start(); at the very top of your page, no spaces... nothing between it...

also, remove your brackets in your echo, that is not good coding practise... and i would use isset in the if statement...

[code=php:0]
if(!isset($_SESSION['username'])){
echo "Log In";
}else{
echo "Log Out";
}
[/code]

:)
[/quote]

according to my experience does not the [b]![/b] command mean not. therefore, shouldnt the code be:
[code]
<?php
session_start();
if(isset($_SESSION['username'])){
echo "Log In";
}else{
echo "Log Out";
}
?>
[/code]
no, because then if the session is set you are asking them to login. you wont to ask them to logout of the session IS set, so we do if the session isn't set (!isset) we show login else show logout because the session will be set.
[quote author=ProjectFear link=topic=120588.msg494857#msg494857 date=1167690428]
no, because then if the session is set you are asking them to login. you wont to ask them to logout of the session IS set, so we do if the session isn't set (!isset) we show login else show logout because the session will be set.
[/quote]
ohhh i didnt read the topic, kk sorry guys.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.