Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6

Thread: globals=Off

  1. #1
    Regular Coder
    Join Date
    Feb 2005
    Posts
    663
    Thanks
    5
    Thanked 14 Times in 14 Posts

    globals=Off

    Hi,

    I'm pretty new to php, and am working with a couple of guides to help me get started. In the guide, it uses method="post" and method="get" in html forms. But i'm learning that with globals=Off in one's php.ini file, that will not work any longer.

    Can someone tell me what the alternative is?

    Thanks
    pt

  • #2
    Regular Coder
    Join Date
    Jun 2005
    Posts
    804
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Both methods will still work with globals off, but the retrieval method is different. When you submit a form, the contents are placed in an array (called $_GET or $_POST, depending on the method used). When register globals is on, the contents of these arrays are automatically turned into global variables that can be instantly accessed; if it's off, they're not, so you have to pull them from their array:

    PHP Code:
    //say we've submitted a POST form with a 
    //text field named 'mytext' filled out with 'myvalue'

    <?php

    //globals on
    echo $mytext;              //returns 'myvalue'
    echo $_POST['mytext']; //returns 'myvalue'

    //globals off
    echo $mytext;              //undefined variable error
    echo $_POST['mytext']; //returns 'myvalue'

    ?>

  • #3
    Regular Coder
    Join Date
    Jan 2005
    Posts
    221
    Thanks
    2
    Thanked 0 Times in 0 Posts
    placing extract($_REQUEST); at the top of a file allows you to access POST or GET variables without the array

  • #4
    Senior Coder
    Join Date
    Apr 2005
    Location
    Colorado, United States
    Posts
    1,208
    Thanks
    0
    Thanked 0 Times in 0 Posts
    And it also just wastes memory on extra variables. You don't want to use $_REQUEST unless you really don't care where the values come from either. $_REQUEST is made up of POST, GET, and COOKIE variables, so always use $_POST, $_GET, $_COOKIE etc. to retrieve values if you care where they came from.
    "$question = ( to() ) ? be() : ~be();"

  • #5
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,639
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Using $_REQUEST reopens the security hole that turning register globals off closes.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #6
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    no it does not.
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)


  •  

    Posting Permissions

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