Results 1 to 2 of 2

Thread: a way to ignore post data when page refreshes

  1. #1
    Join Date
    Nov 2005
    Location
    ankara / turkiye
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default a way to ignore post data when page refreshes

    it is a problem when you post a data from a form, press f5 and the data posts again. how to ignore it. let's see

    make a hidden field with a value of time()
    open a session
    store the post time data in the session

    when you hit F5 the page refreshes but the post time value remains same.
    compare it with the session time value. if they are equal don't use the data.

    when you click submit the time value changes and you will be able to gather information only from a submitted data not refreshed data

    the example

    Code:
    <?php
    /*start a session*/
    session_start();
    
    /*if there's no post set session time value to the recent time*/
    if (!isset($_POST[time])) {$_SESSION[time]=time();}
    
    /*if session time value equals to post time value it means this post is from a refresh*/
    if ($_SESSION[time]==$_POST[time])
    		{echo 'Do not refresh the page';exit();}
    /*if session time value is not equal to the post time value it means that it is from a submit*/
    if ($_SESSION[time]<>$_POST[time])
    		{$_SESSION[time]=$_POST[time];}
    
    echo'
    <form method="post" action="">
    <input type="hidden" name="time" value="'.time().'">
    <input type="submit" value="Submit">
    </form>
    ';
    ?>
    have a good use
    Last edited by cadaver; 09-14-2006 at 02:14 PM.

  2. #2
    Join Date
    Sep 2006
    Location
    Eureka, California
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I also like to add the SELECT() on the last entry into the database and see if it matches the same users_id of the person submitting the new one. Unless you have a website that is not very active, chances are you are going to have someone else post between the time it takes the same person to post two submissions.

    Basically just another method to deal with flood protection.

    John B. Abela

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •