Code: Select all
<input type=\"submit\" id=\"loginbutton\" name=\"Set\" value=\"Set As Userpic\">
if(isset($_REQUEST['Set'])) {
echo $count=count($_REQUEST);
}
Moderator: General Moderators
Code: Select all
<input type=\"submit\" id=\"loginbutton\" name=\"Set\" value=\"Set As Userpic\">
if(isset($_REQUEST['Set'])) {
echo $count=count($_REQUEST);
}
I'm not such a hater. I would say "NEVER use $_REQUEST unless a) you actually want to check GET, POST, or COOKIE, and b) you know for sure which order the variables come in".flying_circus wrote:The first step is to NEVER use $_REQUEST.
Code: Select all
<input type="checkbox" name="checkbox1" />
<input type="checkbox" name="checkbox2" />
<input type="checkbox" name="checkbox3" />Code: Select all
<input type="checkbox" name="checkbox[]" />
<input type="checkbox" name="checkbox[]" />
<input type="checkbox" name="checkbox[]" />Yes, I am a hater, and I fail to see the benefit of using $_REQUEST, especially if we host the application on a server in which we can't control the configuration (and/or change of configuration).tasairis wrote:I'm not such a hater. I would say "NEVER use $_REQUEST unless a) you actually want to check GET, POST, or COOKIE, and b) you know for sure which order the variables come in".flying_circus wrote:The first step is to NEVER use $_REQUEST.
Code: Select all
<html>
<head>
<title>Test</title>
</head>
<body>
<form action="test.php" method="post">
<input type="checkbox" name="checkbox[]" />
<input type="checkbox" name="checkbox[]" />
<input type="checkbox" name="checkbox[]" />
<input type="checkbox" name="checkbox[]" />
<input type="checkbox" name="checkbox[]" />
<br />
<input type="submit" />
</form>
</body>
</html>Code: Select all
test.php?checkbox%5B%5D=on&checkbox%5B%5D=onCode: Select all
<?php
if(isset($_REQUEST['checkbox']))
print "Request Count: " . count($_REQUEST['checkbox']) . "<br />";
if(isset($_POST['checkbox']))
print "Post Count: " . count($_POST['checkbox']) . "<br />";
?>Code: Select all
Request Count: 2
Post Count: 1I don't mean to be a negative nancy, or blunt. I just see the use of the $_REQUEST superglobal in code samples in this forum far too frequently.In particular, the convention has been established that the GET and HEAD methods SHOULD NOT have the significance of taking an action other than retrieval. These methods ought to be considered "safe". This allows user agents to represent other methods, such as POST, PUT and DELETE, in a special way, so that the user is made aware of the fact that a possibly unsafe action is being requested.