Jump to content

how to prevent data insertion when the page is post back


seco

Recommended Posts

Hi

i insert data to my db correctly but when i go to some page and them return to the insert page again a message appear prompts me if i want to send the post data again and if ok it will insert te data again to the db

how to prevent data insertion only if the page is not posted back?

 

thanks in advance.

 

What you could try is store the refering link into a session, something like this:

<?php
session_start();
if($_SESSION['referer'] == "http://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}")
{
    die("please do not go back");

}

$_SESSION['referer'] = $_SERVER['HTTP_REFERER'];
?>

 

I'm not sure if this will work but it's worth a try.

A better idea would be store a session variable in the form page and also insert that same variable into the form. When the form is submitted, you check if the submitted variable in the form is the same as the one stored in the session. If it matches, you insert the new data, and if it doesn't, you give out some sort of error.

 

Once the data has been inserted into the database, simply remove the session variable or save a new value into it, so that attempting to resubmit the same form will not be accepted.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.