www.webdeveloper.com
Results 1 to 11 of 11

Thread: Udefined variables

  1. #1
    Join Date
    Nov 2006
    Posts
    3

    Exclamation Udefined variables

    This is a followup on the thread I've posted last week. The error which I had still persists. I'm working with HTML form and I'm using GET to .php file. Have you guys worked with $HTTP_*_VARS? This is where my problem is, a user selects one of the radio buttons named color on the HTML file and clicks on a button to submit the form. Depending on the radio button the user selected, .php file is going to change the bgcolor of the whole page using switch statement. One of the books I read talks about register_global in the php.ini file, do you guys know how to set this up?

  2. #2
    Join Date
    Apr 2005
    Location
    Bathurst, NSW, Australia
    Posts
    3,357
    "Globals" in laymans just means that you can access the same information just in a quicker way. ie, accessing $HTTP_POST_VARS['radio'] AKA $_POST['radio'] can be simply accessed as $radio.. This *technically* will have no effect on what you are trying to achieve as long as you code it appropriatly although this *can* open security risks. To finish up, in my opinion, you are better off having globals turned off.

    On another note *Moderator Hat On* You are refering to a recent post you have made - what was wrong with that thread? What is the reason in creating a new thread?

  3. #3
    Join Date
    Jun 2006
    Location
    Down at the bottom of the garden
    Posts
    1,239
    Quote Originally Posted by bathurst_guy
    "Globals" in laymans just means that you can access the same information just in a quicker way. ie, accessing $HTTP_POST_VARS['radio'] AKA $_POST['radio'] can be simply accessed as $radio.. This *technically* will have no effect on what you are trying to achieve as long as you code it appropriatly although this *can* open security risks. To finish up, in my opinion, you are better off having globals turned off.

    On another note *Moderator Hat On* You are refering to a recent post you have made - what was wrong with that thread? What is the reason in creating a new thread?
    I want one of them hats too!

  4. #4
    Join Date
    Dec 2006
    Location
    Escaz˙ (Costa Rica) and Mallorca (Spain)
    Posts
    3,234
    Quote Originally Posted by MrCoder
    I want one of them hats too!
    Don't give him one, whatever you do... He just wants to declare my coding habits illegal!

  5. #5
    Join Date
    Jun 2006
    Location
    Down at the bottom of the garden
    Posts
    1,239
    Quote Originally Posted by NightShift58
    Don't give him one, whatever you do... He just wants to declare my coding habits illegal!
    And I would of got away with it too if it weren't for you darn kids!

  6. #6
    Join Date
    Jan 2005
    Location
    Alicante (Spain)
    Posts
    7,739
    Quote Originally Posted by bathurst_guy
    $HTTP_POST_VARS['radio'] AKA $_POST['radio']
    Actually they are not synonomous. $HTTP_POST_VARS is merely a global array while $_POST is a superglobal. That means $HTTP_POST_VARS is not directly available from subroutines such as functions and classes.

  7. #7
    Join Date
    Jun 2006
    Location
    Down at the bottom of the garden
    Posts
    1,239
    Quote Originally Posted by bokeh
    Actually they are not synonomous. $HTTP_POST_VARS is merely a global array while $_POST is a superglobal. That means $HTTP_POST_VARS is not directly available from subroutines such as functions and classes.
    Why do people still use $HTTP_POST_VARS?
    I always use $_POST.

  8. #8
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,220
    EDIT: ignore the following, I was confused by the example I was looking at in the manual.
    $HTTP_POST_VARS requires that register_globals be enabled. As the default setting since PHP 4.2.0 is "off" for register_globals, thus essentially deprecating its use, for best script portability you should eschew the use of $HTTP_POST_VARS and instead use $_POST or $_GET as applicable.
    Last edited by NogDog; 01-29-2007 at 02:13 PM.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  9. #9
    Join Date
    Jan 2005
    Location
    Alicante (Spain)
    Posts
    7,739
    Quote Originally Posted by NogDog
    $HTTP_POST_VARS requires that register_globals be enabled.
    No it doesn't. I'm running PHP5 regiser globals off and that array is present. Here's a test script for you:
    PHP Code:
    <?php

    function GET()
    {
        echo 
    "\n <h1>Local scope: </h1>\n<p><b>\$HTTP_GET_VARS: </b><br>\n";
        
    var_dump($HTTP_GET_VARS);
        echo 
    "</p>\n<p> <b>\$_GET: </b><br>\n";
        
    var_dump($_GET);
        echo 
    '</p>';
    }

    echo 
    "\n <h1>Global scope: </h1><p><b>\$HTTP_GET_VARS </b><br>\n";
    var_dump($HTTP_GET_VARS);
    echo 
    "</p>\n<p> <b>\$_GET: </b><br>\n";
    var_dump($_GET);
    echo 
    '</p>';

    GET();
    ?>
    It prints:

    Global scope:

    $HTTP_GET_VARS
    array(1) { ["my_variable"]=> string(8) "my_value" }

    $_GET:
    array(1) { ["my_variable"]=> string(8) "my_value" }

    Local scope:

    $HTTP_GET_VARS:

    NULL

    $_GET:
    array(1) { ["my_variable"]=> string(8) "my_value" }

  10. #10
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,220
    Crap...my bad. I was looking at the 2nd example on this page and thought the comment that actually applies to the echo $username line applied to the $HTTP_POST_VARS line above the comment. I guess between the fact that I've always just used the $_POST array and hadn't finished my first cup of coffee when I wrote that conspired against me.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  11. #11
    Join Date
    Jan 2005
    Location
    Alicante (Spain)
    Posts
    7,739
    From my php.ini
    Code:
    ; You should do your best to write your scripts so that they do not require
    ; register_globals to be on;  Using form variables as globals can easily lead
    ; to possible security problems, if the code is not very well thought of.
    register_globals = Off
    
    ; Whether or not to register the old-style input arrays, HTTP_GET_VARS
    ; and friends.  If you're not using them, it's recommended to turn them off,
    ; for performance reasons.
    register_long_arrays = On
    I think PHPBB and PHPBB2 are two of the reasons most servers still have those arrays enabled.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles