note 67191 modified in function.setcookie by danbrown

From: Date: Sun, 17 May 2009 17:57:53 +0000
Subject: note 67191 modified in function.setcookie by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-155044@lists.php.net to get a copy of this message
You can use cookies to prevent a browser refresh repeating some action from a form post... (providing the client is cookie enabled!) <?php //Flag up repeat actions (like credit card transaction, etc) if(count($_POST)>0) { $lastpost= isset($_COOKIE['lastpost']) ? $_COOKIE['lastpost'] : ''; if($lastpost!=md5(serialize($_POST))) { setcookie('lastpost', md5(serialize($_POST))); $_POST['_REPEATED']=0; } else { $_POST['_REPEATED']=1; } } //At this point, if $_POST['_REPEATED']==1, then the user //has hit the refresh button; so don't do any actions that you don't //want to repeat! ?> Hope that helps :) Gareth --was-- You can use cookies to prevent a browser refresh repeating some action from a form post... (providing the client is cookie enabled!) //Flag up repeat actions (like credit card transaction, etc) if(count($_POST)>0) { $lastpost= isset($_COOKIE['lastpost']) ? $_COOKIE['lastpost'] : ''; if($lastpost!=md5(serialize($_POST))) { setcookie('lastpost', md5(serialize($_POST))); $_POST['_REPEATED']=0; } else { $_POST['_REPEATED']=1; } } //At this point, if $_POST['_REPEATED']==1, then the user //has hit the refresh button; so don't do any actions that you don't //want to repeat! Hope that helps :) Gareth http://php.net/manual/en/function.setcookie.php

« previous php.notes (#155044) next »