$_GET won't read my hidden field

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bass-man

    #1

    $_GET won't read my hidden field

    I am trying to include a dynamically changeable file in my website with
    PHP and Javascript so I am using a hidden field to hold the name of the
    file I want to include, and I am using the$_GET function to read the
    hidden field, but it says the field has no value even though I have a
    default value in the field. So my question is how do I get PHP to read
    the value of a hidden field?

  • Ken Robinson

    #2
    Re: $_GET won't read my hidden field


    bass-man wrote:[color=blue]
    > I am trying to include a dynamically changeable file in my website[/color]
    with[color=blue]
    > PHP and Javascript so I am using a hidden field to hold the name of[/color]
    the[color=blue]
    > file I want to include, and I am using the$_GET function to read the
    > hidden field, but it says the field has no value even though I have a
    > default value in the field. So my question is how do I get PHP to[/color]
    read[color=blue]
    > the value of a hidden field?[/color]

    Can we see the code that is failing? Without it, we can't do much more
    than guess...

    Ken

    Comment

    • bass-man

      #3
      Re: $_GET won't read my hidden field

      Here's the code

      //include the file
      <?php include('calend ar/' . $e); ?>

      //hidden field
      <input name="ev" type="hidden" id="ev" value="noE.htm" >

      //get the value
      $e = $_GET['ev'];

      and it shows the following eror:

      Warning: main(calendar/): failed to open stream: No such file or
      directory in /asdf/asdf/public_html/index.php on line 206

      Warning: main(calendar/): failed to open stream: No such file or
      directory in /asdf/asdf/public_html/index.php on line 206

      Warning: main(): Failed opening 'calendar/' for inclusion
      (include_path=' .:/usr/lib/php:/usr/local/lib/php') in
      /asdf/asdf/public_html/index.php on line 206

      Comment

      • Ken Robinson

        #4
        Re: $_GET won't read my hidden field


        bass-man wrote:[color=blue]
        > Here's the code
        >
        > //include the file
        > <?php include('calend ar/' . $e); ?>
        >
        > //hidden field
        > <input name="ev" type="hidden" id="ev" value="noE.htm" >
        >
        > //get the value
        > $e = $_GET['ev'];[/color]

        Are these lines cut out of a larger program or do they exist exactly in
        this order?

        Remember, PHP is executes on the SERVER and Javascript on the client.
        By the time Javascript sees the source, PHP is long gone.

        For this to work, you need something like:
        <?
        $e = (isset($_GET['ev']))?$_GET['ev']:'noE.htm');
        include ('calendar/' . $e);
        //
        // ...
        //
        echo '<form method="GET" action="' . $_SERVER['PHP_SELF'] . '">' .
        "\n";
        echo '<input name="ev" type="hidden" id="ev" value="noE.htm" >'."\n";
        //
        // rest of form
        //
        echo '<input name="submit" value="Submit"> '."\n";
        echo '</form>'."\n";
        ?>

        [color=blue]
        >
        > and it shows the following eror:
        >
        > Warning: main(calendar/): failed to open stream: No such file or
        > directory in /asdf/asdf/public_html/index.php on line 206
        >
        > Warning: main(calendar/): failed to open stream: No such file or
        > directory in /asdf/asdf/public_html/index.php on line 206
        >
        > Warning: main(): Failed opening 'calendar/' for inclusion
        > (include_path=' .:/usr/lib/php:/usr/local/lib/php') in
        > /asdf/asdf/public_html/index.php on line 206[/color]

        Those errors occur because the first time the program is executed, the
        variable '$e' is NULL. The line:

        $e = (isset($_GET['ev']))?$_GET['ev']:'noE.htm');

        will initialize $e to "noE.htm" if the the form hasn'nt been submitted
        yet.

        Ken

        Comment

        • bass-man

          #5
          Re: $_GET won't read my hidden field

          They are cut from a larger program, the include is in a one cell and
          not in a form, the hidden field is in a different cell in a form, and
          the $_GET is at the top above every thing else. What I have is a
          calendar, and I want to be able to click each day of the calendar and
          in a different cell see the events of that day, without reloading the
          page. On each of the days of the calendar I have javascript onClick
          that changes the value of the 'ev' hidden field. If you can suggest a
          fix or an alternative I would be much obliged. Thanks.

          Comment

          • Kenneth Downs

            #6
            Re: $_GET won't read my hidden field

            bass-man wrote:
            [color=blue]
            > I am trying to include a dynamically changeable file in my website with
            > PHP and Javascript so I am using a hidden field to hold the name of the
            > file I want to include, and I am using the$_GET function to read the
            > hidden field, but it says the field has no value even though I have a
            > default value in the field. So my question is how do I get PHP to read
            > the value of a hidden field?[/color]

            $_POST ?

            Is your hidden field inside of a form? What is the method of the form?

            Usually $_GET returns the parms that were put into the URL, like


            $_POST returns the parms that were in a <form> element, because forms are
            almost always submitted with a method of "post".


            --
            Kenneth Downs
            Secure Data Software, Inc.
            (Ken)nneth@(Sec )ure(Dat)a(.com )

            Comment

            • bass-man

              #7
              Re: $_GET won't read my hidden field

              Yes the field is in a form, and it is POST, I have tried using $_POST
              and that doesn't work either. I've also tried using form method GET.

              Comment

              • Brion Vibber

                #8
                Re: $_GET won't read my hidden field

                bass-man wrote:[color=blue]
                > //include the file
                > <?php include('calend ar/' . $e); ?>
                >
                > //hidden field
                > <input name="ev" type="hidden" id="ev" value="noE.htm" >[/color]

                This is very insecure; an attacker could modify the form to read back
                any file on your system readable by the web server.

                If you include files based on client input, you really need to carefully
                validate the value before using it.

                -- brion vibber (brion @ pobox.com)

                Comment

                Working...