View Full Version : globals=Off

01-04-2006, 10:28 PM

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?


Kid Charming
01-04-2006, 10:59 PM
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:

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


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

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


01-05-2006, 12:34 AM
placing extract($_REQUEST); at the top of a file allows you to access POST or GET variables without the array

Velox Letum
01-05-2006, 12:51 AM
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.

01-05-2006, 10:52 PM
Using $_REQUEST reopens the security hole that turning register globals off closes.

01-06-2006, 03:43 AM
no it does not.