Jump to content

Simple Session Help


herghost

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.