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)) Link to comment https://forums.phpfreaks.com/topic/105097-solved-getting-http-url-passed-variables/ Share on other sites More sharing options...
DarkWater Posted May 11, 2008 Share Posted May 11, 2008 $var = $_GET['var']; echo $var; //Outputs: foo Link to comment https://forums.phpfreaks.com/topic/105097-solved-getting-http-url-passed-variables/#findComment-538036 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? Link to comment https://forums.phpfreaks.com/topic/105097-solved-getting-http-url-passed-variables/#findComment-538037 Share on other sites More sharing options...
DarkWater Posted May 11, 2008 Share Posted May 11, 2008 No. Link to comment https://forums.phpfreaks.com/topic/105097-solved-getting-http-url-passed-variables/#findComment-538038 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 | Link to comment https://forums.phpfreaks.com/topic/105097-solved-getting-http-url-passed-variables/#findComment-538041 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.