$_REQUEST[]具用$_POST[] $_GET[]的功能,但是$_REQUEST[]比较慢。通过POST和GET方法提交的所有数据都可以通过$_REQUEST数组获得
前端代码(使用php动态生成表单域)
<?php
/* Program name: form_phone.inc
* Description: Defines a form that collects a user's
* name and phone number.
*/
$labels = array( "first_name" => "First Name",
"middle_name" => "Middle Name",
"last_name" => "Last Name",
"phone" => "Phone");
$submit = "Submit Phone Number";
?>
<html>
<head>
<title>Customer Phone Number</title>
<style type='text/css'>
<!--
#form {
margin: 1.5em 0 0 0;
padding: 0;
}
#field {padding-bottom: 1em;}
label {
font-weight: bold;
float: left;
width: 20%;
margin-right: 1em;
text-align: right;
}
-->
</style>
</head>
<body>
<h3>Please enter your phone number below.</h3>
<form action='process_form.php' method='POST'>
<div id='form'>
<?php
/* Loop that displays the form fields */
foreach($labels as $field => $label)
{
//总是对文本域设置maxlength可以预防恶意攻击
echo "<div id='field'><label for='$field'>$label</label>
<input id='$field' name='$field' type='text'
size='50%' maxlength='65' /></div>\n";
}
echo "</div>\n";
echo "<input style='margin-left: 33%' type='submit'
value='$submit' />\n";
?>
</form>
</body>
</html>
后端代码
<?php
echo "<html>
<head><title>Form Fields</title></head>
<body>";
echo "<ol>";
foreach($_POST as $field => $value)
{
echo "<li> $field = $value</li>";
}
echo "</ol>";
?>
</body></html>