Posted on 2006-04-08
Last Modified: 2010-05-18
unset($HTTP_POST_VARS) doesn't work

How can i unset my post variables?
Question by:tolgaong
    LVL 49

    Expert Comment

    You can try and use:

    $HTTP_POST_VARS = array();

    But not sure what you mean. What do you expect to be happening after you do the unset.

    Also, $HTTP_POST_VARS has been replaced with the $_POST array. $HTTP_POST_VARS still works I guess, but $_POST is prefered. Same as $_GET is preferred in favour of $HTTP_GET_VARS and there are $_SESSION and $_COOKIE and $_ENV as well.

    LVL 9

    Author Comment

    if (checkPosts($postarray)){
          if ($_SESSION["fullname"]!=$namesurname){
                $db->updateSQL("update ".PREFIX.ADMINUSERS." set fullname='$namesurname' where uid=$dbuserid");
                $HTTP_POST_VARS=array();            }
          else {
                $t->assign('message',"Girmiş olduğunuz isim önceki isminiz ile aynıdır.");

    When I refresh the page it enters the statement again. If i could be able to unset it, It wouldn't enter the first statement(checkPosts -> my function to check posted values).  
    LVL 6

    Accepted Solution

    You can't unset() $HTTP_POST_VARS, because it's superglobal variable.

    As said Roonaan, you can simply assign it to array()
    But you have to remember that: "...$HTTP_POST_VARS contains the same initial information, but is not an autoglobal. (Note that HTTP_POST_VARS and $_POST are different variables and that PHP handles them as such)..." (c) PHP Manual.

    So you can write simple function:
    function cleanPostVars()
        if (isset($HTTP_POST_VARS)) $HTTP_POST_VARS = array();
        if (isset($_POST)) $_POST = array();

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
    This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
    The viewer will learn how to count occurrences of each item in an array.
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now