alecks Posted May 11, 2008 Share Posted May 11, 2008 I need to clear this up in my mind, because I have heard so many conflicting answers from online references: What is the proper way to retrieve HTTP passed variables (http://www.test.com/index.php?var=foo) within a PHP script? (so that it will work with PHP 6 (register_globals gone)) Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 11, 2008 Share Posted May 11, 2008 $var = $_GET['var']; echo $var; //Outputs: foo Quote Link to comment Share on other sites More sharing options...
alecks Posted May 11, 2008 Author Share Posted May 11, 2008 $var = $_GET['var']; echo $var; //Outputs: foo Would global $var; also work? Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 11, 2008 Share Posted May 11, 2008 No. Quote Link to comment Share on other sites More sharing options...
maxudaskin Posted May 11, 2008 Share Posted May 11, 2008 No... $_POST is when your form method is post. $_GET is when your form method is get. All variables are confined to a function if they are created in one, unless you use global to change it from a local variable (in one function) to a global variable (used in the whole script). <?php function localVar(){ $localvar = "local"; echo "localVar : " . $localvar; echo "<br />"; } function globalVar(){ global $globalvar; $globalvar = "global"; echo "globalVar : " . $globalvar; echo "<br />"; } localVar(); globalVar(); echo $globalvar . " | " . $localvar; ?> outputs localVar : local globalVar : global global | Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.