...

View Full Version : globals=Off



ptmuldoon
01-04-2006, 09:28 PM
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

Kid Charming
01-04-2006, 09: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'

<?php

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

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

?>

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

Velox Letum
01-04-2006, 11:51 PM
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.

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

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum