<!--以下是index.php页面-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<form action="test_page.php" method="post" >
<input type="text" name="name">
<input type="text" name="pwd">
<input type="hidden" name="submit" value=1>
<input type="submit" value="提交" >
</form>
</body>
</html>
<!--以下是test_page.php页面-->
<script language="javascript">
function chkiput(form)
{
if(form.name.value=="")
{
alert("请输入用户名!");
form.name.select();
return(false);
}
if(form.pwd.value=="")
{
alert("请输入用户密码!");
form.pwd.select();
return(false);
}
return(true);
}
</script>
<?php
if($_POST[submit]!="")
{
class chkinput
{ private $name;
private $pwd;
function __construct($x,$y) //实现数据成员初始化
{$this->name=$x;
$this->pwd=$y;
}
function checkinput()
{
if($this->name=="1" &&$this->pwd=="2")
{ echo "<br><div align=center>恭喜您,登录成功!</div>"; }
else
{ echo "<br><div align=center>对不起,密码输入错误!</div>"; }
}
}
$obj=new chkinput($name=$_POST[name],$pwd=$_POST[pwd]);
$obj->checkinput();
}
?>
loading