Jump to content

Just a Simple Newbie Question


livethedead

Recommended Posts

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.  ;)

Link to comment
https://forums.phpfreaks.com/topic/256550-just-a-simple-newbie-question/
Share on other sites

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?

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)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.