0

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.

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by djjjozsi
0

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 topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.