浏览器端的数据采集主要依靠html的form表单来实现,form表单是包含一系列表单元素的区域,表单元素是允许用户在表单中输入信息的元素。常见的表单有文本域,下拉列表,单选框和复选框等。
示例register.html
<html lang='en'>
<head>
<title>用户注册</title>
<meta charset="UTF-8">
</head>
<body>
<form action='./register.php' method='post'>
用户名:<input type='text' name='userName'/><br/>
密 码:<input type='password' name='passWord'/><br/>
确认密码:<input type='password' name='confirmPassword'/><br/>
<input type='submit' value='提交'/>
<input type='reset' value='重置'/>
</form>
</body>
</html>
以上表单用来供用户输入信息注册信息,而接收到数据后,需要使用一个程序来处理数据,即使用post方法讲数据提交给register.php。
示例register.php
<?php
//接收来自register.html的数据信息
$userName=$_POST['userName'];
$password=$_POST['passWord'];
$confirmPassword=$_POST['confirmPassword'];
//判断用户输入的两次密码是否一致
if($password == $confirmPassword){
echo 'Registered successfully!';
}else{
echo 'The password is different from confirmPassword';
}
?>
以上程序使用$_post预定义变量接收来自html表单的数据,并进行简单的判断两次密码是否一致。