Form Data Loss

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • smilemaster

    Form Data Loss

    I have recently started experiencing form data loss. Here is an
    example:

    ====test_form1. php====

    <form method="POST" action="test_fo rm2.php">
    <input name="textboxva lue" type="text" size="20">
    <br>
    <input type="submit" value="Submit">
    </form>

    =============== =======


    ====test_form2. php====
    <?
    echo "textboxval ue: ".$textboxvalue ;
    ?>
    =============== =======

    (note: these are incomplete examples, I have left out the <html> tags
    for example)

    After putting in data into the textboxvalue textbox and pressing the
    submit button, on the second page only "textboxval ue: " is displayed.
    The weird thing is that when I restart my computer, this works fine,
    but then stops working again. These pages are encrypted with 128 SSL
    encryption (mod_SSL 2.8.15).

    This problem has plagued an online app that I am developing and is a
    company-wide problem that happens on computers in other offices too.

    Here's my info:

    SERVER
    Apache 1.3.28
    PHP 4.3.6
    MySQL 3.23.39
    mod_SSL 2.8.15
    phpMyAdmin 2.50

    CLIENT
    Windows XP Pro
    Internet Explorer 6.0.28
  • Marian Heddesheimer

    #2
    Re: Form Data Loss

    On 21 Jun 2004 10:03:55 -0700, kcox@issllc.com (smilemaster) wrote:
    [color=blue]
    >====test_form2 .php====
    ><?
    >echo "textboxval ue: ".$textboxvalue ;
    >?>
    >============== ========[/color]
    [color=blue]
    >submit button, on the second page only "textboxval ue: " is displayed.[/color]

    i suppose you have turned off "register_globa ls" in your php.ini
    Either turn it on or use the $_POST Array (which is the better
    solution):

    echo "textboxval ue: ".$_POST['textboxvalue'];

    Regards
    Marian


    --
    Tipps und Tricks zu PHP, Coaching und Projektbetreuun g
    Da ich mich seit einiger Zeit aus der Programmierung von Websites zurückgezogen habe, sind meine Tutorials und Schulungsinhalte nicht mehr länger verfügbar, da sie inzwischen veraltet sind.

    Comment

    • smilemaster

      #3
      Re: Form Data Loss

      Sorry for such a newbee question, but why is using the $_Post Array
      better?

      Also, I checked "register_globa ls" and it is set to "On" both for the
      "Local Value" and the "Master Value".

      Thanks,

      -Karl



      Marian Heddesheimer <200604.8.nolin k@spamgourmet.c om> wrote in message news:<ek6ed0tnk cuaifbrhf3cvm2j c9f2joagk9@4ax. com>...[color=blue]
      > On 21 Jun 2004 10:03:55 -0700, kcox@issllc.com (smilemaster) wrote:
      >[color=green]
      > >====test_form2 .php====
      > ><?
      > >echo "textboxval ue: ".$textboxvalue ;
      > >?>
      > >============== ========[/color]
      >[color=green]
      > >submit button, on the second page only "textboxval ue: " is displayed.[/color]
      >
      > i suppose you have turned off "register_globa ls" in your php.ini
      > Either turn it on or use the $_POST Array (which is the better
      > solution):
      >
      > echo "textboxval ue: ".$_POST['textboxvalue'];
      >
      > Regards
      > Marian[/color]

      Comment

      • Malcolm Dew-Jones

        #4
        Re: Form Data Loss

        smilemaster (kcox@issllc.co m) wrote:
        : I have recently started experiencing form data loss. Here is an
        : example:


        : CLIENT
        : Windows XP Pro
        : Internet Explorer 6.0.28

        I could be way off base, but I seem to recall reading about exactly this
        problem with IE. For whatever reason, under certain conditions it doesn't
        send the data from the form to the server.

        Is it possible that the version of IE has changed recently? If other
        things changed, such as whether http was changed to https, then this would
        also explain why you see it now and not before, but even then, the problem
        could be IE.

        I would try the pages using another browser to see it that changes
        anything.

        $0.02

        Comment

        • bonehead

          #5
          Re: Form Data Loss

          smilemaster wrote:[color=blue]
          > I have recently started experiencing form data loss. Here is an
          > example:[/color]

          and Marian Heddesheimer replied:[color=blue]
          >i suppose you have turned off "register_globa ls" in your php.ini[/color]

          smile: Marian's answer is almost certainly the correct one. Especially
          since you report that this is something you "recently started
          experiencing". Check with your server admin and ask if they recently
          upgraded the machine to a newer version of php or whatever unix flavor
          os it's (presumably) got. I believe that php 4.2.0 was the first
          revision where register_global s is turned off by default.

          I discovered this the hard way by working through a Wrox book on php.
          register_global s is a php.ini setting that allows all variable values
          passed through either forms or urls to be recognized as global variables
          by default. Well, this creates all sorts of security problems which is
          why it's normally recommended that you turn this feature *off* in the
          php.ini. When you do this, it means that if you want to access a value
          passed through a form field, you must access it through either the POST
          or REQUEST global arrays, and if you want to access a value passed
          through a url, you must access it through either the GET or REQUEST
          global arrays, thus:

          //value passed through form field text box named 'myfield'
          $myvalue=$_POST['myfield'];

          //value passed through url, i.e.,
          //"http://www.myurl.net/test.php?myfiel d=myvalue"
          $myvalue=$_GET['myfield'];

          Not only that, but if you need to pass any values acquired in this
          manner to a function, they need to be explicitly declared as global
          within the function, thus:

          function myFunctionName () {
          global $myvalue;
          }

          See the following errata page from Wrox for an explanation (refer to the
          second entry on the errata listing):


          Also see the following documentation on www.php.net (be sure to scroll
          to the bottom of the page to the section headed 'SECURITY: NEW INPUT
          MECHANISM'):
          PHP is a popular general-purpose scripting language that powers everything from your blog to the most popular websites in the world.


          Also see this page and refer to the big box headed 'Warning':


          As you can see, as of revision 4.2.0, register_global s is turned *off*
          by default, and you absolutely should leave it that way. Just revise
          your code per the examples above.

          Comment

          • Bathroom_Monkey

            #6
            Re: Form Data Loss

            I checked my phpinfo() page and "register_globa ls" is set to "On" both
            for the "Local Value" and the "Master Value".

            Also, I updated my test pages with a $_POST reference, here ya go:

            ===test_form1.p hp===
            <form method="POST" action="test_fo rm2.php">
            <input name="textboxva lue" type="text" size="20">
            <input type="submit" value="Submit">
            </form>

            ===test_form2.p hp===
            <?
            echo "textboxval ue: ".$textboxvalue ;
            echo "<br>textboxval ue (Post Array): ".$_POST['textboxvalue'];
            //<--NEW
            ?>

            Again, these codes samples are incomplete for clarity's sake (for
            example I've left out the <HTML> tages).

            I contacted the company that hosts the pages for me (Yahoo!
            Webhosting) and because the above pages were working at the time they
            tried them, they could not replicate my problem and therefore refused
            to help further.

            The super weird thing about this problem is that it only happens
            *sometimes*. Like today I've been working on the PHP app I am
            developing and it's worked fine except for on two occasions when it
            stopped working and I had to reboot.

            Another fact to add to the "super weird" file is that when this
            problem starts, it occurs in multiple types of browsers. When it
            started last time I tried the above test pages in IE6.0, Mozilla, and
            Opera with the *same* results in all of them (it didnt work).

            Also, like I said before, this problem has happened across my company
            at computers in different offices with different ISPs. The only
            corrolation I can think of is that all of the machines we have run XP
            Pro.

            I'm about to pull my remaining hair out! :-(

            Comment

            • Michael Austin

              #7
              Re: Form Data Loss

              smilemaster wrote:[color=blue]
              > I have recently started experiencing form data loss. Here is an
              > example:
              >
              > ====test_form1. php====
              >
              > <form method="POST" action="test_fo rm2.php">
              > <input name="textboxva lue" type="text" size="20">
              > <br>
              > <input type="submit" value="Submit">
              > </form>
              >
              > =============== =======
              >
              >
              > ====test_form2. php====
              > <?
              > echo "textboxval ue: ".$textboxvalue ;
              > ?>
              > =============== =======
              >
              > (note: these are incomplete examples, I have left out the <html> tags
              > for example)
              >
              > After putting in data into the textboxvalue textbox and pressing the
              > submit button, on the second page only "textboxval ue: " is displayed.
              > The weird thing is that when I restart my computer, this works fine,
              > but then stops working again. These pages are encrypted with 128 SSL
              > encryption (mod_SSL 2.8.15).
              >
              > This problem has plagued an online app that I am developing and is a
              > company-wide problem that happens on computers in other offices too.
              >
              > Here's my info:
              >
              > SERVER
              > Apache 1.3.28
              > PHP 4.3.6
              > MySQL 3.23.39
              > mod_SSL 2.8.15
              > phpMyAdmin 2.50
              >
              > CLIENT
              > Windows XP Pro
              > Internet Explorer 6.0.28[/color]

              what OS is the server running?

              Michael Austin.

              Comment

              • Bathroom_Monkey

                #8
                Re: Form Data Loss

                The server is running FreeBSD 4.8

                -Karl

                [color=blue][color=green]
                > > Here's my info:
                > >
                > > SERVER
                > > Apache 1.3.28
                > > PHP 4.3.6
                > > MySQL 3.23.39
                > > mod_SSL 2.8.15
                > > phpMyAdmin 2.50
                > >
                > > CLIENT
                > > Windows XP Pro
                > > Internet Explorer 6.0.28[/color]
                >
                > what OS is the server running?
                >
                > Michael Austin.[/color]

                Comment

                • Michael Austin

                  #9
                  Re: Form Data Loss

                  Bathroom_Monkey wrote:
                  [color=blue][color=green][color=darkred]
                  >>>Here's my info:
                  >>>
                  >>>SERVER
                  >>>Apache 1.3.28
                  >>>PHP 4.3.6
                  >>>MySQL 3.23.39
                  >>>mod_SSL 2.8.15
                  >>>phpMyAdmin 2.50
                  >>>
                  >>>CLIENT
                  >>>Windows XP Pro
                  >>>Internet Explorer 6.0.28[/color]
                  >>
                  >>what OS is the server running?
                  >>
                  >>Michael Austin.[/color]
                  >
                  >
                  >
                  > The server is running FreeBSD 4.8
                  >
                  > -Karl
                  >
                  >
                  >[/color]


                  Okay, there have been several suggestions about turning on error
                  checking. What did that yield?

                  With the latest version of PHP (4.3.something) I started using the
                  following code at the top of all of my scripts just to make sure I get
                  all of the variables...

                  <?php
                  // comment the following lines to turn off error messaging
                  error_reporting (E_ALL);
                  ini_set('displa y_errors', 1);
                  if (!empty($_GET))
                  {
                  extract($_GET);
                  }
                  else if (!empty($HTTP_G ET_VARS))
                  {
                  extract($HTTP_G ET_VARS);
                  }
                  if (!empty($_POST) )
                  {
                  extract($_POST) ;
                  }
                  else if (!empty($HTTP_P OST_VARS))
                  {
                  extract($HTTP_P OST_VARS);
                  }
                  ......
                  ?>

                  But before you do change test_form2.php to:

                  <?
                  echo "POST textboxvalue: ".$_POST["textboxval ue"]; //more transportable
                  echo "GET textboxvalue: ".$_GET["textboxval ue"]; //coding style.
                  ?>

                  What does this give you??


                  Michael Austin.

                  Comment

                  • Bathroom_Monkey

                    #10
                    Re: Form Data Loss

                    Error checking has yielded very little. After adding the GET
                    statement to the php code, here is what the error message is when this
                    problem is occuring:

                    =============== =============== ======
                    Notice: Undefined variable: textboxvalue in
                    /ssl/TEST_nb_TEST/test_form2.php on line 39
                    textboxvalue:


                    Notice: Undefined index: textboxvalue in
                    /ssl/TEST_nb_TEST/test_form2.php on line 43
                    textboxvalue (Post Array):
                    Notice: Undefined index: textboxvalue in
                    /ssl/TEST_nb_TEST/test_form2.php on line 44

                    GET textboxvalue:
                    =============== =============== ======


                    In this revision of fixing this problem, here is what my code looks
                    like in test_form2.php:


                    =============== =============== ======
                    <?
                    // comment the following lines to turn off error messaging
                    error_reporting (E_ALL);
                    ini_set('displa y_errors', 1);
                    if (!empty($_GET))
                    {
                    extract($_GET);
                    }
                    else if (!empty($HTTP_G ET_VARS))
                    {
                    extract($HTTP_G ET_VARS);
                    }
                    if (!empty($_POST) )
                    {
                    extract($_POST) ;
                    }
                    else if (!empty($HTTP_P OST_VARS))
                    {
                    extract($HTTP_P OST_VARS);
                    }

                    ?>

                    <html>

                    <head>
                    <meta name="GENERATOR " content="Micros oft FrontPage 5.0">
                    <meta name="ProgId" content="FrontP age.Editor.Docu ment">
                    <meta http-equiv="Content-Type" content="text/html;
                    charset=windows-1252">
                    <title>TEST FORM PAGE 2</title>
                    </head>

                    <body>


                    <br><br>
                    <?
                    echo "textboxval ue: ".$textboxvalue ;

                    echo "<br><br>";

                    echo "textboxval ue (Post Array): ".$_POST['textboxvalue'];
                    echo "<br>GET textboxvalue: ".$_GET['textboxvalue'];
                    ?>


                    </body>

                    </html>

                    =============== =============== ======

                    Comment

                    • Pedro Graca

                      #11
                      Re: Form Data Loss

                      Bathroom_Monkey wrote:[color=blue]
                      > <?
                      > echo "textboxval ue: ".$textboxvalue ;[/color]

                      echo 'textboxvalue: ',
                      isset($_REQUEST['textboxvalue'])
                      ? $_REQUEST['textboxvalue']
                      : '(no_textboxval ue)';

                      /* The array $_REQUEST is a combination of $_COOKIE, $_GET, and $_POST
                      * in an order determined by your PHP configuration */

                      /* But I really prefer to treat those arrays separately */
                      [color=blue]
                      > echo "<br><br>";
                      >
                      > echo "textboxval ue (Post Array): ".$_POST['textboxvalue'];[/color]

                      echo 'textboxvalue (Post Array): ',
                      isset($_POST['textboxvalue'])
                      ? $_POST['textboxvalue']
                      : '(no_POST_textb oxvalue)';
                      [color=blue]
                      > echo "<br>GET textboxvalue: ".$_GET['textboxvalue'];[/color]

                      echo '<br>GET textboxvalue: ',
                      isset($_GET['textboxvalue'])
                      ? $_GET['textboxvalue']
                      : '(no_GET_textbo xvalue)';
                      [color=blue]
                      > ?>[/color]

                      --
                      USENET would be a better place if everybody read: | to email me: use |
                      http://www.catb.org/~esr/faqs/smart-questions.html | my name in "To:" |
                      http://www.netmeister.org/news/learn2quote2.html | header, textonly |
                      http://www.expita.com/nomime.html | no attachments. |

                      Comment

                      • Michael Austin

                        #12
                        Re: Form Data Loss

                        Bathroom_Monkey wrote:
                        [color=blue]
                        > Error checking has yielded very little. After adding the GET
                        > statement to the php code, here is what the error message is when this
                        > problem is occuring:
                        >
                        > =============== =============== ======
                        > Notice: Undefined variable: textboxvalue in
                        > /ssl/TEST_nb_TEST/test_form2.php on line 39
                        > textboxvalue:
                        >
                        >
                        > Notice: Undefined index: textboxvalue in
                        > /ssl/TEST_nb_TEST/test_form2.php on line 43
                        > textboxvalue (Post Array):
                        > Notice: Undefined index: textboxvalue in
                        > /ssl/TEST_nb_TEST/test_form2.php on line 44
                        >
                        > GET textboxvalue:
                        > =============== =============== ======
                        >
                        >
                        > In this revision of fixing this problem, here is what my code looks
                        > like in test_form2.php:
                        >
                        >
                        > =============== =============== ======
                        > <?
                        > // comment the following lines to turn off error messaging
                        > error_reporting (E_ALL);
                        > ini_set('displa y_errors', 1);
                        > if (!empty($_GET))
                        > {
                        > extract($_GET);
                        > }
                        > else if (!empty($HTTP_G ET_VARS))
                        > {
                        > extract($HTTP_G ET_VARS);
                        > }
                        > if (!empty($_POST) )
                        > {
                        > extract($_POST) ;
                        > }
                        > else if (!empty($HTTP_P OST_VARS))
                        > {
                        > extract($HTTP_P OST_VARS);
                        > }
                        >
                        > ?>
                        >
                        > <html>
                        >
                        > <head>
                        > <meta name="GENERATOR " content="Micros oft FrontPage 5.0">
                        > <meta name="ProgId" content="FrontP age.Editor.Docu ment">
                        > <meta http-equiv="Content-Type" content="text/html;
                        > charset=windows-1252">
                        > <title>TEST FORM PAGE 2</title>
                        > </head>
                        >
                        > <body>
                        >
                        >
                        > <br><br>
                        > <?
                        > echo "textboxval ue: ".$textboxvalue ;
                        >
                        > echo "<br><br>";
                        >
                        > echo "textboxval ue (Post Array): ".$_POST['textboxvalue'];
                        > echo "<br>GET textboxvalue: ".$_GET['textboxvalue'];[/color]

                        phpinfo(); // add this to your code - email it directly to me
                        // as you may not want this viewable to everyone.[color=blue]
                        > ?>
                        >
                        >
                        > </body>
                        >
                        > </html>
                        >
                        > =============== =============== ======[/color]

                        This has got to be a platform and or php ini problem. I just cut/pasted
                        your code and it works for me... see the above addition and comments

                        Again the question: do you have control over setting the environment
                        variables and/or system/php/mysql configuration variables?

                        Michael Austin.

                        Comment

                        • smilemaster

                          #13
                          Re: Form Data Loss

                          I don't have control over the server variables (php.ini, etc.) as the
                          servers are hosted by Yahoo! Webhosting. I checked the variables that
                          everyone has talked about however (like the keep alive, etc.) and they
                          are all set "correctly" already.

                          -Karl

                          Comment

                          • Michael Austin

                            #14
                            Re: Form Data Loss

                            smilemaster wrote:
                            [color=blue]
                            > I don't have control over the server variables (php.ini, etc.) as the
                            > servers are hosted by Yahoo! Webhosting. I checked the variables that
                            > everyone has talked about however (like the keep alive, etc.) and they
                            > are all set "correctly" already.
                            >
                            > -Karl[/color]


                            is Yahoo! Webhosting willing to make changes to the server to allow you
                            to execute your code?

                            Okay, we are going to try this one more time using this code...
                            basically the same thing only condensed into one php file instead of two.

                            <?
                            // comment the following lines to turn off error messaging
                            error_reporting (E_ALL);
                            ini_set('displa y_errors',1);
                            if (!empty($_GET))
                            {
                            extract($_GET);
                            }
                            else if (!empty($HTTP_G ET_VARS))
                            {
                            extract($HTTP_G ET_VARS);
                            }
                            if (!empty($_POST) )
                            {
                            extract($_POST) ;
                            }
                            else if (!empty($HTTP_P OST_VARS))
                            {
                            extract($HTTP_P OST_VARS);
                            }

                            if (isset($flag) && ($flag > 0))
                            {
                            echo "textboxval ue: ".$textboxvalue ."<br>";
                            echo "<br><br>";
                            if (isset($_POST['textboxvalue']))
                            {
                            echo "textboxval ue (Post Array):
                            ".$_POST['textboxvalue']."<br>";
                            }
                            else { echo "POST TEXTBOX VALUE NOT SET<br>";
                            }
                            if (isset($_GET['textboxvalue']))
                            {
                            echo "textboxvalue:( Get Array)
                            ".$_GET['textboxvalue']."<br>";
                            }
                            else { echo "GET TEXTBOX VALUE NOT SET<br>"; }
                            echo "<form method=post><br ><center>";
                            echo "<input type=hidden name=flag value=0 >";
                            echo "<input TYPE=submit value=Back></center>";

                            echo "</form>";
                            // phpinfo();

                            }
                            else {
                            echo "<form method=GET>";
                            echo "<input name=textboxval ue type=text size=20>";
                            echo "<br>";
                            echo "<input type=hidden name=flag value=1>";
                            echo "<input type=submit value=Submit> </form>";
                            }
                            ?>

                            if this doesn't work, I suggest bringing up your own server...

                            Michael Austin.

                            Comment

                            • Bathroom_Monkey

                              #15
                              Re: Form Data Loss

                              I think I could probably work with them to make some changes, I'd have
                              to know what to ask for, however. All of the reccommendation s on this
                              thread already exist it their settings.
                              [color=blue]
                              >
                              > is Yahoo! Webhosting willing to make changes to the server to allow you
                              > to execute your code?
                              >
                              >[/color]

                              Comment

                              Working...