CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2001
    Location
    Bremen, Germany
    Posts
    314

    Question Can I clear $_POST superglobal?

    Hi

    I wonder whether there is a way to clear the $_POST superglobal array or even set an array element to a new value.

    I've got a self-referencing form where the user can enter some text and that is calling itself. I decide whether the page was initially displayed by something like this:
    Code:
    	if ( (isset($_POST["Submit"]) == TRUE) && ($_POST["Submit"] = 'Say') )
    But once the user has submitted the form, $_POST["Submit"] will still be set when the page is reloaded (without pressing the submit button).

    Is there a straigtforward way to clear or somehow modify the superglobal to prevent resubmit on reload? As you might expect, unset($_POST["Submit"]) or $_POST["Submit"]='none' does not work...

    Thank you in advance

    Oliver.

  2. #2
    Join Date
    May 2003
    Location
    Denmark
    Posts
    1,315

    Re: Can I clear $_POST superglobal?

    If I am understanding you correctly, you seem to think that the $_post variable stays the same through several http requests, because it stays on the server. I can assure you this is incorrect, the $_post variable always holds the http post variables from the current http request.

    The reason you are seeing the same value again after a reload, is most likely that the browser repeats the same http request that was used to load the page (in this case the submit from the previous page).
    The biggest problem encountered while trying to design a system that was completely foolproof,
    was, that people tended to underestimate the ingenuity of complete fools.
    Douglas Adams

  3. #3
    Join Date
    May 2003
    Posts
    8

    Re: Can I clear $_POST superglobal?

    It'd be better to use $_SESSION's variable for what you want (if I understand correctly)

  4. #4
    Join Date
    Nov 2004
    Posts
    4

    Re: Can I clear $_POST superglobal?

    i think you are reffering to the fact that some users hit the refresh button and it tries to repost the data again to page. its a common problem with blogs that refresh to the same page..... if you want to make it so that when they hit the refresh key after posting something just redirect them to that page after you have done the neccessary code.


    like either with

    <code here>
    header( "Location: http://pageyouwanthere" );

    or make a page after the post that they click a link on to get back to the page you want them to be at.

    quite like many forums do.

  5. #5
    Join Date
    Nov 2004
    Posts
    26

    Re: Can I clear $_POST superglobal?

    unset() $_POST['Submit'] and then use header(), that should work.

    Also change:

    (isset($_POST["Submit"]) == TRUE)

    to

    (isset($_POST["Submit"]))
    Last edited by Danii; November 20th, 2004 at 09:19 AM.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured