Ok I have been trying for hours and hours to stop my image upload script from uploading the same image whenever a user refreshes the page.

I have tried unlink, unset and redirecting the user and back. It still won't quit. I have literally unset every single input element in my script but the form still submits the previous image when the page is refreshed.

I was told to use unlink by someone but unlink just returns the following error:

Warning: unlink() [function.unlink]: No error in c:\program files\....

I even tried to attach a user submitted validation to the script by making them solve a simple addition question but even this didn't work because for some reason unset didn't stop the variables from being removed.

after the user submitted the form, and the textfield and file upload field has filled, insert into the table, and use redirect:

header("Location: success.php");

another way, is to implement a refresh check used by the submit time.

add a hidden field into the form:

<input type="hidden" name="hiddentime" value="<?php echo time();?>">

if submit has pressed:

<?php
session_start();

if(!empty($_POST["submit"]))
{
    if ( empty( $_POST["hiddentime"] ) ) {
        die( "timestamp is missing!" );
    } else {
        $hidd = $_POST["hiddentime"];
        if ( isset( $_SESSION["time_$hidd"] ) )
            die("Do not refresh the page!");
        else
            $_SESSION["time_$hidd"] = 1;
    }

//the rest of the code
}

?>
This article has been dead for over six months. Start a new discussion instead.