Log in

View Full Version : Resolved unset Refresh



bluewalrus
06-17-2010, 02:24 AM
Is there a way I can unset a variable on a refresh?

I have this code but it keeps updating my record, so I think the unset must not be processing.



if (isset($_POST['pending']) && isset($_POST['requestor'])) {
$task = $_POST['pending'];
$requestor = $_POST['requestor'];
$date = date("n/d/y g+1:i:s a");
$request_file = '2bedone.txt';
$current_file = file_get_contents($request_file);
$pattern = '/<\/td>\n\t<\/tr>\n<\/table>/';
$replacement = "</td>\n\t</tr>\n\t\t<td>$task</td>\n\t\t<td>$date</td>\n\t\t<td id=\"user\">$requestor</td>\n\t</tr>\n</table>";
$current_file = preg_replace($pattern, $replacement, $current_file);
file_put_contents($request_file, $current_file);
unset($_POST['pending']);
unset($_POST['requestor']);
}

djr33
06-17-2010, 02:27 AM
To the server, a refresh is the same as a new request. It only differs in the browser. The only way to approach this is to use Javascript or to somehow track requests on the server. You could do md5(serialize($_REQUEST).serialize($_SERVER)) and if that same request is made within 1 minute then ignore it. At least that's a rough idea of how to approach it. But there's no easy way.

If you force a redirect after they submit this, then they won't be refreshing the submission but just the redirect. That's a common way to avoid this.


All you are doing in the code above is deleting those variables during the current page load. Then the next time if the browser sends them again, they will be in the PHP again.