Small problem with sessions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
leebo
Forum Commoner
Posts: 44
Joined: Sun Oct 20, 2002 9:49 am

Small problem with sessions

Post by leebo »

OK i have page1.php with form fields filled in with data from mysql.

<input type="text" name="location" size="30" value="<? echo($row[18]);?>"> etc.etc..........

I use the following to validate user:

<? session_start();
if ( session_is_registered ("myuser") )
{


when the form goes to the other page ( page2.php ) the data is displayed on page2 fine but.................

If they decide to go back and change something on page1.php when sent to page2 again the changes have not been applied because of the session saves the values from page1 on the first submit......

How can i change the session so it will keep changing values if they hit the back button ? Or will a refresh work on page2 ? if so whats the code ??

Thanks
torpedo51
Forum Newbie
Posts: 3
Joined: Thu Mar 13, 2003 2:11 am
Location: Surf City, CA

Post by torpedo51 »

I think you are experiencing your browser's ability to cache what was on the page, and not a session "storing" your form element values (unless you explicity saved the values to session variables yourself?).

You need to decide whether you want to use the GET or POST method to move your values from page1 to page2. As a rule of thumb... use GET when navigating around your site, and use POST when the values are going to to be written to your database.

When you use POST, you will not really be able to hit the 'back' button.. at least not without getting a warning from your browser that, "this page was created using [POST] values which may no longer be available, do you want to reload the page anyway?"...

Hope this gets you pointed in the right direction.
leebo
Forum Commoner
Posts: 44
Joined: Sun Oct 20, 2002 9:49 am

Post by leebo »

I am using post but dont get any errors when hiting the back button ! I have tried GET but doesn`t seem to work at all ! I'm confused 8O :!:
bionicdonkey
Forum Contributor
Posts: 132
Joined: Fri Jan 31, 2003 2:28 am
Location: Sydney, Australia
Contact:

Post by bionicdonkey »

if you go back in your browsers history to a page which as hadform data submitted and the POST data is still set, you should get an error stating that the page has expired. the only way to get the data back in the form would be to print the stored values back into the form.
Post Reply