I have a problem with a feedback script like the ones they have at the bottom of the function pages on http://www.php.net They let people input there comments at the bottom of a web page.
Anyway the problem is that the user fills out the form and submits it (it posts to itself) and the new post it displayed along with the rest but if you press the refresh button at this point the sscript will add the post twice. I have tried unsetting the posted variables ( unset($var)) but that dosent work.
any ideas?
feedback form
Moderator: General Moderators
- protokol
- Forum Contributor
- Posts: 353
- Joined: Fri Jun 21, 2002 7:00 pm
- Location: Cleveland, OH
- Contact:
How do you store each post? Do you insert them into a database???
Or you could use sessions:
Now, even if the user reloads the page, the new message will not be posted because the $_SESSION['posted'] will be TRUE, which doesn't match the above condition, and therefore, doesn't add the new message.
Or you could use sessions:
Code: Select all
session_start();
if (isset($_SESSIONї'posted']) && $_SESSIONї'posted'] == false) {
// post message code here
$_SESSIONї'posted'] = true;
}You could try redirecting to a "thank you" page, so that when the user clicks refresh, it reloads the "thank you" page instead of resubmitting the data.
(See http://www.php.net/manual/en/function.header.php for more information about the header() function)
(You might also want to see a similar thread at http://www.devnetwork.net/forums/viewtopic.php?t=1410 )
Code: Select all
$thank_you_page = "thank_you.php";
$new_location = "http://".$_SERVERї'HTTP_HOST'].dirname($_SERVERї'PHP_SELF'])."/".$thank_you_page;
header("Location: $new_location");