Using Back button, page is "out of date".How to av

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
Wentu
Forum Newbie
Posts: 11
Joined: Sun Feb 02, 2003 1:09 pm

Using Back button, page is "out of date".How to av

Post by Wentu »

Hi

i can't understand how to realize a simple script that allows to go back and "remember" the previous state after i sent some variables with a script. In many sites i see pages that (apparently, but i could be wrong since i am a newbie) call themselves after submitting a form but if i press back i can actually see the page where i was before, maybe with some out of date infos.
So what's wrong with this little code ?

Code: Select all

<?php
session_start();

if(!isset($_SESSION['visit']))
	{$_SESSION['visit'] = 1;}
else
	{$_SESSION['visit']++;}


if(isset($_POST['choice']))
	{
	echo "This is visit number #",$_SESSION['visit'],"<br />";
	echo "Last time you choosed:",$_POST['choice'],"<br />";
	}
 else
 {
	 $_POST['choice'] = "yes" ;
 }

echo'<form action = "',$_SERVER["PHP_SELF"],'" method = post>';
?>
Choose:<br />
<select name = "choice">
<option value = "yes"

Code: Select all

<?php if($_POST['choice'] == "yes") echo "selected"; ?>
>YES</option>
<option value = "no"

Code: Select all

<?php if($_POST['choice'] == "no") echo "selected"; ?>
>NO</option>
</select>

<input type = "submit" value = "Send">
</form>



When I press "back" button it says the page is "out of date" (well, i don't know the precise sentence in english ) because some info were sent through a form. It says "press reload" but then the visit number has of course increased of 1.
Is it possible to accomplish a real "step back" to see a previous page ?

thankx a lot !

Wentu
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Post by Bill H »

The following at the top of each page will prevent the "out of date" issue, but I'm not sure it will preserve the visit number.

Code: Select all

<?php
session_cache_limiter("private,must-revalidate");
?>
jollyjumper
Forum Contributor
Posts: 107
Joined: Sat Jan 25, 2003 11:03 am

Post by jollyjumper »

Hi,

It also helps when using method=get instead of post in your forms.

Greetz Jolly.
Post Reply