i have a code that upload picture and preview a image that in the same pages,
how can i prevent a user double upload image when he press F5 ?
thanks.
how can i prevent a user double upload image when he press F5 ?
thanks.
| Philip wrote: |
| i have a code that upload picture and preview a image that in the same pages,
how can i prevent a user double upload image when he press F5 ? |
| Code: |
| <?php
session_start(); if (!isset($_SESSION['count'])) { $_SESSION['count'] = 0; } ?> |
| Code: |
| <?php
if (++$_SESSION['count'] != $_POST['nodblpost']) { exit('Please do not double post. Thank you.'); } ?> |
| Code: |
|
<form ...> <input type="hidden" name="nodblpost" value="<?php echo $_SESSION['count']+1; ?>"> <!-- other form fields and whatnot --> </form> |
| Code: |
| header('Expires: Tue, 28 Mar 1978 07:04:00 GMT'); // That's my birthday, pick any date in the past.
header('Last-Modified: ' . gmdate("D, d M Y H:i:s") . ' GMT'); header('Cache-Control: no-store, no-cache, must-revalidate'); header('Cache-Control: post-check=0, pre-check=0', false); header('Pragma: no-cache'); header('Location: page_to_redirect_to.php'); |
| Philip wrote: |
| thanks to hexkid its work |
| Philip wrote: |
| anyway how does it work ? ?? ?? |
| hexkid wrote: |
| when you display the form to the user you get a variable with a value ($_POST['nodblpost'] = 1 for the first time) which is compared with the server version of the same variable ($_SESSION['count'] = 1); if the user refreshes the page only $_SESSION['count'] wil be incremented, and the comparison with $_POST['nodblpost'] will identify a mismatch. |