herghost Posted September 6, 2010 Share Posted September 6, 2010 Hi all, I am trying to display a link if a user is logged in or not etc, here is my code: <div id="nav"> <a href="">My Account</a> <?php if ($_SESSION['logged'] !="1") { ?> | <a href="scripts/login.php" onclick="return GB_showCenter('Login', this.href, 200, 400)">Login</a>| <a href="scripts/reg.php" onclick="return GB_showCenter('Register', this.href, 280,550)">Register</a> <?php } else { } ?>| <a href="">Contact</a>| <a href="scripts/logout.php" onclick="return GB_showCenter('Logout', this.href, 200, 400)">Logout</a> </div> Basically this all works if the user is logged in, the reg and login links are not shown, however if no user is logged in then I get an error saying the session is an undefined index. I am guessing that i have to say 'only if the user is logged in then check this', iI think i do this with isset but not sure on how I include the ! clause in a isset statement. Any help would be greatly appreciated! Thanks Link to comment https://forums.phpfreaks.com/topic/212704-simple-session-help/ Share on other sites More sharing options...
herghost Posted September 6, 2010 Author Share Posted September 6, 2010 Not to worry: <div id="nav"> <?php if(isset($_SESSION['logged'])) { ?> <a href="scripts/logout.php" onclick="return GB_showCenter('Logout', this.href, 200, 400)">Logout</a> |<a href="">My Account</a> <?php } else { ?> | <a href="scripts/login.php" onclick="return GB_showCenter('Login', this.href, 200, 400)">Login</a>| <a href="scripts/reg.php" onclick="return GB_showCenter('Register', this.href, 280,550)">Register</a> <?php } ?>| <a href="">Contact</a> </div> Link to comment https://forums.phpfreaks.com/topic/212704-simple-session-help/#findComment-1108031 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.