tjmbc Posted May 4, 2008 Share Posted May 4, 2008 **warning: newbie thoughts exist beyond this point** I have a logout link that destroys a session: if (isset($_SESSION['Username'])){ echo "Welcome back ".$_SESSION['fname']."!"; echo "<a href='http://www.domain.com/index.php?sign_out=yes'>Sign out.</a>"; } else{ echo (A sign in form.); } That statement gets processed on the same page with this: if (isset($_GET['sign_out'])){ session_destroy(); } After the link is clicked and the session is destroyed, the link to 'sign out' still appears on the page. When I click it again, it then displays the 'sign IN' form that it's supposed to. So basically, I have to click the 'sign out' link twice to get it to disappear and show the 'sign in' form. All of my links seem to do the same thing. For instance, I have a link that, when clicked, deletes a row from mysql. I have to click the link twice to make the link not appear on my page, but I know from querying the database after the first click that the row was deleted already. Any help would be appreciated. Even if you could just tell me what it's called that I'm doing wrong so I can find some tutorials or something. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 4, 2008 Share Posted May 4, 2008 Let us see the code where you make the login/logout links. I think I know the problem already, but I need to see your code. Quote Link to comment Share on other sites More sharing options...
tjmbc Posted May 4, 2008 Author Share Posted May 4, 2008 <?php //If user is already logged in, show welcome message and logout option. if (isset($_SESSION['Username'])){ echo "Welcome back ".$_SESSION['fname']."!<br />"; echo "<a href='http://www.domain.com/index.php?sign_out=yes'>Sign out.</a>"; } else{ echo "<form id='form1' name='form1' method='POST' action='$_SERVER['PHP_SELF'];'><label> Email:<br /> <input type='text' name='email' id='email' /> Password:<br /> <input type='password' name='password' id='password' /><br /> <div align='right'> <input type='submit' name='button' id='button' value='Submit' /> </div></label></form>"; } ?> Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 4, 2008 Share Posted May 4, 2008 Does that code come before the logout code? If it does, then $_SESSION['username'] will still be set when that part of the code executes. And use double quotes on your <a> tags. Escape them if you have to. Quote Link to comment Share on other sites More sharing options...
tjmbc Posted May 4, 2008 Author Share Posted May 4, 2008 Thank you. You were right, my ordering of statments was wrong. So I don't run accross this again, I stopped messing with 'php_self' processing my forms and just made a seperate form processing page for my site. This solved the problems for all of my pages. I think for us beginners this is the way to go. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 4, 2008 Share Posted May 4, 2008 Heh. =P Any time. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.