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
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?

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.