Re: VERY IMPORTANT: Sessions in Pages with a Form !

From: Date: Thu, 28 Sep 2000 14:27:31 +0000
Subject: Re: VERY IMPORTANT: Sessions in Pages with a Form !
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-17809@lists.php.net to get a copy of this message
Maxim Maletsky wrote: > > Hello list, > > I have a big trouble: > > When I use sessions on a page that also has a form in it the back button > doesn't work. Like when a subscriber gets an error from my script saying > that he didn't fill the form out completely and he tries to hit back button > of his browser the whole form disappears. Every single field becomes empty. > > I know for sure that it is something that has to do with sessions, since > commenting them, back button will show you "your" form and not an empty one. > > here's a piece of code I combined to explain you what I meant: > > <? > session_start(); > session_register("location"); > > if($Submit) > { > echo 'Submitted Staff:<P>'; > echo $text.'<BR>'; > echo $textarea.'<BR>'; > echo $location.'<P>'; > echo 'Now, check this out: click <A HREF="javascript:history.back()">back > button</A> and see if the text you were typing is still there...'; > } else { > ?> > > <FORM METHOD="POST" ACTION="<?=$PHP_SELF?>"> > <BR>Text: <INPUT TYPE="text" NAME="test"> > <BR>Text Area: <TEXTAREA NAME="textarea" ROWS="2" > COLS="20"></TEXTAREA> > <BR><INPUT TYPE="submit" NAME="Submit" VALUE="Submit This > Form"> > </FORM> > > <? > $location = $SCRIPT_NAME; > } > ?> > > If you try it you should then see that on back button what you just filled > in the form will be gone. > Comment the session start/register and it will work. > > It is very important for me to resolve this problem, since we saw a BIG drop > in subscriptions since I started using sessions in the pages using forms. > I know few ways to fix it, like: registering the sessions with the field > values, outputting the data again when there's an error, recording the data > submitted and prompting only for the missing one.. but, it's hard to explain > why, I REALLY NEED the back button to work with sessions just like it would > be without them, > A couple of things spring to mind here, although to be honest I can't figure out exactly how they relate to your problem, I am just throwing some ideas around. 1. Maybe the issue all has to do with the cacheing of web pages locally in your browser. Somebody yesterday referred me to an excellent article on how web pages are cached. (http://www.mnot.net/cache_docs) One of the things it mentioned is that if you use POST in a form, the browser will not cache the page, hence going "back" to it, it will always reload a fresh copy. Try using GET instead. 2. If you have a session variable with the same name as a POST variable, the session variable will override the POST variable. I don't know if this is really related to your problem, but looking at what you are trying to do, you might bump into this one. If you really want to access the POST variable, you have to specifically refer to the HTTP_POST_VARS array. 3. Since you seem to be using JavaScript anyway, why not do the nicest possible solution for your end users by writing a JavaScript routine to validate the input before the page is actually submitted back to the web server. Hope this helps Kevin

« previous php.general (#17809) next »