Results 1 to 2 of 2

Thread: unset Refresh

  1. #1
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default unset Refresh

    Is there a way I can unset a variable on a refresh?

    I have this code but it keeps updating my record, so I think the unset must not be processing.

    PHP Code:
        if (isset($_POST['pending']) && isset($_POST['requestor'])) {
            
    $task =  $_POST['pending'];
            
    $requestor $_POST['requestor'];
            
    $date date("n/d/y g+1:i:s a");
            
    $request_file '2bedone.txt';
            
    $current_file file_get_contents($request_file);
            
    $pattern '/<\/td>\n\t<\/tr>\n<\/table>/';
            
    $replacement "</td>\n\t</tr>\n\t\t<td>$task</td>\n\t\t<td>$date</td>\n\t\t<td id=\"user\">$requestor</td>\n\t</tr>\n</table>";
            
    $current_file preg_replace($pattern$replacement$current_file);
            
    file_put_contents($request_file$current_file);
            unset(
    $_POST['pending']);
            unset(
    $_POST['requestor']);
        } 
    Last edited by bluewalrus; 06-17-2010 at 03:29 AM.
    Corrections to my coding/thoughts welcome.

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    To the server, a refresh is the same as a new request. It only differs in the browser. The only way to approach this is to use Javascript or to somehow track requests on the server. You could do md5(serialize($_REQUEST).serialize($_SERVER)) and if that same request is made within 1 minute then ignore it. At least that's a rough idea of how to approach it. But there's no easy way.

    If you force a redirect after they submit this, then they won't be refreshing the submission but just the redirect. That's a common way to avoid this.


    All you are doing in the code above is deleting those variables during the current page load. Then the next time if the browser sends them again, they will be in the PHP again.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. The Following User Says Thank You to djr33 For This Useful Post:

    bluewalrus (06-17-2010)

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
  •