Results 1 to 4 of 4

Thread: PHP problem while handling HTTP data from the user

  1. #1
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default PHP problem while handling HTTP data from the user

    Hello All,

    The code snippet below seems to be very simple

    **************Code Snippet Starts from here*********************

    <?php
    if($submit == "Go")
    {
    echo("You wrote ". $you_wrote);
    echo("<br> You could have done whatever you want with the input instead");
    exit;
    }
    else
    {
    echo("Nothing happend<br>");
    }

    ?>
    <form action="input.php" method="POST" name="f1">
    Input a word <input type="text" size="20" name="you_wrote">
    <input type="submit" name="submit" value="Go">
    </form>

    **************Code Snippet Ends here**************************

    Whenever I enter something into the textbox and press 'Go' button it prints "Nothing Happend" and the form that contains a Textbox and a Go button.

    According to some PHP books the above code should work. I am trying to handle the data from the user without using $_POST and $_GET php system based arrays.

    Any help would be appreciated

    Regards

    Code Exploiter

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

    Default

    Note that the [code] tag on this board will allow you to post code. (actually, [php] will do better for php)



    The page the action points to, input.php is the current page, the one the code above is from, correct?


    Using the "register_globals" setting, submitted elements from a form will be automatically set, like from name="blah" to $blah.
    However, if that is not set, which I am guessing is the case in your script, that will not happen.
    Instead, the value of that will be available through $_POST['name'].

    Either replace the above variables with post variables like that, or set the variables at the top, like:
    $name = $_POST['name'];
    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. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    I am trying to handle the data from the user without using $_POST and $_GET php system based arrays.
    Why on Earth would you want to do that? $_POST and $_GET are much easier to handle, and far more portable and secure than using register_globals (the configuration setting on which you're relying in the above code). A similar effect can be achieved by adding:
    Code:
    foreach($_POST as $k => $v) {
      $$k = $v;
      global $$k;
    }
    ... to the top of the page, but as mentioned, it's not a good idea, since in some situations a malicious user could use it to override important variables in the script that you trust.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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

    Default

    Hmm... yeah. It may seem like it's a lot more work to use the GET/POST variables, but it really isn't and gives you control over what's going on, plus it makes more sense as you get used to using them... so... I'd stick with them.
    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

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
  •