Jump to content

pages aren't refreshing properly


tjmbc

Recommended Posts

**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.

Link to comment
Share on other sites

            <?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>";

}

?>

Link to comment
Share on other sites

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.

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.