livethedead Posted February 6, 2012 Share Posted February 6, 2012 Hey there, I just started learning PHP as my first language and after being on different forums for several years I know that you can learn a lot from the knowledge of the communities so I figure may aswell be here on my PHP endeavour. I'm not computer/code illiterate so no need to dumb anything down. My question is about this little script: <?php foreach($_REQUEST as $value) { echo $value; } ?> I fully understand what it does, I just don't understand how really. What confuses me is how is anything in the $_REQUEST array as I didn't specify/ how does $_REQUEST know what information to pull. <label for="first_name">First Name:</label> <input type="text" name="first_name" size="20"/><br /> <label for="last_name"><Last Name:</label> <input type="text" name="last_name" size="20"/><br /> <label for="email">Email Address:</label> <input type="text" name="email" size="50"/><br /> Appreciate any explanations for my newbie self. Quote Link to comment https://forums.phpfreaks.com/topic/256550-just-a-simple-newbie-question/ Share on other sites More sharing options...
AyKay47 Posted February 6, 2012 Share Posted February 6, 2012 this will explain. http://php.net/manual/en/reserved.variables.request.php Quote Link to comment https://forums.phpfreaks.com/topic/256550-just-a-simple-newbie-question/#findComment-1315169 Share on other sites More sharing options...
livethedead Posted February 6, 2012 Author Share Posted February 6, 2012 I looked through that aswell as $_GET and $_POST. I understand what $_REQUEST does, just not how. Like $_REQUEST['email'] I get. What has me stumped is how is $_REQUEST realising to go through the HTML labels? I may have answered my own question, does $_REQUEST inherently go through all labels unless specified? Quote Link to comment https://forums.phpfreaks.com/topic/256550-just-a-simple-newbie-question/#findComment-1315170 Share on other sites More sharing options...
AyKay47 Posted February 6, 2012 Share Posted February 6, 2012 when a form is submitted, it sends a $_GET or $_POST request to the server. $_GET, $_POST, and $_REQUEST are superglobal arrays that contain the values sent to the server via a $_GET or $_POST method, ($_REQUEST holds both) as associative. So when your input values are sent to the server via your form being submitted (using $_GET or $_POST methods), $_REQUEST is populated with that data, and you retrieve it using the name of the input as the key name, ($_REQUEST['name of input']). Pay attention to this notice in the manual: Note: The variables in $_REQUEST are provided to the script via the GET, POST, and COOKIE input mechanisms and therefore could be modified by the remote user and cannot be trusted. The presence and order of variables listed in this array is defined according to the PHP variables_order configuration directive. using $_REQUEST is not recommended, it is recommended to use the proper method ($_GET or $_POST) Quote Link to comment https://forums.phpfreaks.com/topic/256550-just-a-simple-newbie-question/#findComment-1315173 Share on other sites More sharing options...
livethedead Posted February 6, 2012 Author Share Posted February 6, 2012 Ahhh much love man, thank you. Quote Link to comment https://forums.phpfreaks.com/topic/256550-just-a-simple-newbie-question/#findComment-1315174 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.