Jump to content

Preventing an Index Form Reload


Pedro999

Recommended Posts

Hi, Just joined the forum. Am new to PHP. Been reading the books,etc, and written a simple program.

 

On the index page I do Start_Session() at the top. I then call a function to log a new visitor by adding a record in a MySQL table. Also call a function to display the visitor number.

 

One the hyperlinks on index.php allows a user to login. If successful various $_SESSION[ ] variables are set. The user is then taken back to the index.php uisng the header statement. The $_SESSION[ ] variables are set ok and are visible in index.php.

 

The question I have, is this. When the user is sent back to index.php, the Add_New_Visitor and Display_Visitor_No functions get called again. How do I stop this? This also happens if the header function is not used and the user is allowed to navigate back to index.php using the browser back arrow key.

 

Thought of doing something like:

 

<? session_start()

if ($_SESSION['login']!='Yes') 

{

Add_Visitor();

etc

}

 

Is there something easy I should be doing here and something fundamental I am not appreciating?

 

Another question occurs is how do I code a logout?  

 

Pedro

Link to comment
Share on other sites

look into the use of isset() - to check if login has occured - and unset() and session_destroy() for the logout.

 

Hi Muddy, have not tested fully, but what you have suggested appears to be working and has solved the problem. Thank you.

 

Before, instead of using isset(), I was using empty(). The subtleties of PHP, and the ignorance of the newby, I guess!

 

Cheers

 

Pedro

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.