register.html
登录主界面
<!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>
<style type="text/css">
table.pos_abs
{
position: absolute;
left: 60%;
top: 30%;
background-color:rgb(224,220,219,0.5);
border-radius: 20px;
text-align: center;
}
.text
{
background-color: rgb(224,220,219,0);
border: 0;
border-bottom: 1px black solid;
}
</style>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>登录界面</title>
</head>
<body background="http://picture.ik123.com/uploads/allimg/180327/12-1P32G61437.jpg"width="1918" height="901">
<table bgcolor="white"
class="pos_abs"
width="20%">
<form method="post" action="./phpcheck.php">
<tr>
<td>账号</td>
<td frame="below"><input type="text" id="name" name="account" placeholder="Username" size="20" class="text" ></td>
</tr>
<tr>
<td>密码</td>
<td ><input id="password" type="password" name="password" placeholder="Password" size="20" class="text"></span></td>
</tr>
<tr>
<td></td>
<td>
<input type="checkbox">记住密码
<input type="checkbox">自动登录
</td>
</tr>
<tr>
<td><p>性别:</p></td>
<td align="center">
<input type="radio" name="sex" value="Male">Male
<input type="radio" name="sex" value="Female">Female
</td>
</tr>
<tr>
<td>
<select class="text">
<option value="phone">phone</option>
<option value="QQ">QQ</option>
<option value="wechat">wechat</option>
</select>
</td>
<td>
<input type="text" name="AccountClass" placeholder="AccountClass" class="text">
</td>
</tr>
<tr>
<td>验证码:</td>
<td>
<input type="text" name="authcode" class="text">
<img id="captcha.php" border="1" src="./captcha.php">
</td>
</tr>
<tr>
<td align="right">
<input type="submit" onclick="return checkform()" value="登录" >
</td>
<td align="center">
<a href="login.html">注册</a>
</td>
</tr>
</form>
</table>
</body>
</html>
captcha.php
验证码板块
<?php
//必须至于顶部,多服务器端记录验证码信息,便于用户输入后做校验
session_start();
//默认返回的是黑色的照片
$image = imagecreatetruecolor(100, 30);
//将背景设置为白色的
$bgcolor = imagecolorallocate($image, 255, 255, 255);
//将白色铺满地图
imagefill($image, 0, 0, $bgcolor);
//空字符串,每循环一次,追加到字符串后面
$captch_code='';
//验证码为随机四个数字
for ($i=0; $i < 4; $i++) {
$fontsize=6;
$fontcolor=imagecolorallocate($image,rand(0,120),rand(0,120),rand(0,120));
//产生随机数字0-9
$fontcontent = rand(0,9);
$captch_code.= $fontcontent;
//数字的位置,0,0是左上角。不能重合显示不完全
$x=($i*100/4)+rand(5,10);
$y=rand(5,10);
imagestring($image,$fontsize,$x,$y,$fontcontent,$fontcolor);
}
//全局变量,以便后续比对
$_SESSION['vcode'] = $captch_code;
//为验证码增加干扰元素,控制好颜色,
//点
for ($i=0; $i < 200; $i++) {
$pointcolor = imagecolorallocate($image,rand(50,200),rand(50,200),rand(50,200));
imagesetpixel($image, rand(1,99), rand(1,29), $pointcolor);
}
//为验证码增加干扰元素
//线
for ($i=0; $i < 3; $i++) {
$linecolor = imagecolorallocate($image,rand(80,220),rand(80,220),rand(80,220));
imageline($image, rand(1,99), rand(1,29),rand(1,99), rand(1,29) ,$linecolor);
}
header('content-type:image/png');
//以png格式输出图片
imagepng($image);
//销毁
imagedestroy($image);
?>
phpcheck.php
验证表单数据
<?php
header("content-type:text/html;charset=utf-8");
session_start();
require_once ('sql.php');
$sql="SELECT *FROM myform";
$result=mysqli_query($con,$sql);
$code=strtolower($_POST['authcode']);
$str=strtolower($_SESSION['vcode']);
$account=strtolower($_POST['account']);
$password=strtolower($_POST['password']);
if($account==""){
echo "<script>alert('请填写用户名');</script>";
echo "<script>location='register.html'</script>";
}
else
{
if ($password=="") {
echo "<script>alert('请输入密码');</script>";
echo "<script>location='register.html'</script>";
# code...
}
else
{
if($code!=$str)
{
echo "<script>alert('验证码输入错误');</script>";
echo "<script>location='register.html'</script>";
}
else
{
//循环数据库表单中用户名密码与输入框中的内容做比对
while($colum=mysqli_fetch_array($result))
{
if(($colum['username']==$account)&&($colum['password']==$password))
{
echo "<script>alert('登陆成功');</script>";
echo "<script>location='message.html'</script>";
}
}
echo "<script>alert('用户名或密码错误');</script>";
echo "<script>location='register.html'</script>";
}
}
}
?>
register1.php
注册界面
<?php
require_once'sql.php';
$account=$_POST['account'];
$password=$_POST['password'];
$resure=$_POST['resurepassword'];
if($account==""||$password=="")
{
echo "<script>alert('账号或密码不能为空')</script>";
}
else
{
if($password!=$resure)
{
echo "<script>alert('两次输入的密码不一致,请重新输入')</script>";
echo "<a href='login.html'>重新输入</a>";
}
else
{
//设置执行mysql的语句
$sql="INSERT INTO myform(username,password)VALUES('$account','$password')";
//执行sql语句
$result=mysqli_query($con,$sql);
//如果语句为空则失败返回注册界面
if(!$result)
{
echo "注册失败";
echo "<script>location='login.html'</script>";
}
else
{
echo "注册成功";
}
}
}
?>
message.html
留言板界面
<!DOCTYPE html>
<html>
<style>
table.form1{
background-color:rgb(224,220,219,0.5);
position:absolute;
left: 60%;
top: 30%;
}
.form{
background-color: rgb(224,220,219,0);
border: 0;
border-bottom: 1px black solid;
}
.form2{
background-color: rgb(224,220,219,0);
}
</style>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body background="http://picture.ik123.com/uploads/allimg/180327/12-1P32G61437.jpg"width="1918" height="901">
<table class="form1">
<form action="record.php" method="post" >
<tr>
<td>
<label>输入你的名字</label>
</td>
<td>
<input type="text" name="yourname" class="form">
</td>
</tr>
<tr>
<td>
<label>输入你的留言</label>
</td>
<td>
<textarea rows=8 cols=20 name="message" class="form2" >
</textarea>
<td>
</tr>
<tr>
<td></td>
<td align="left"><input type="submit"></td>
<!跳转页面显示留言内容>
<td ><input type="button" value="查看留言" onclick="window.open('show.php')"></td>
</tr>
</form>
</table>
</body>
</html>
record.php
记录留言板内容
<?php
header("content-type:text/html;charset=utf-8");
require_once'sql.php';
$name=($_POST['yourname']);
$message=($_POST['message']);
//将留言名字和内容加入数据库
$sql="INSERT INTO content(name,tent)VALUES('$_POST[yourname]','$_POST[message]')";
if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error());
}
echo "<script>alert('留言成功')</script>";
echo "<script>location='message.html'</script>";
mysqli_close($con);
?>
show.php
显示留言板内容
<?php
header("content-type:text/html;charset=utf-8");
//加载sql.php代码块
require_once'sql.php';
$result=mysqli_query($con,"SELECT *FROM content");
echo "<body background='http://pic35.photophoto.cn/20150627/0008020377561267_b.jpg' width='1918' height='901'>";
echo "<table class='table table-hover'>
<thead>
<tr>
<th scope='col'>#Number</th>
<th scope='col'>姓名</th>
<th scope='col'>留言内容</th>
</tr>
</thead>
<tbody>";
//循环数据库中的表单,显示所有元素
//mysqli_fetch_array相当于每次取出表单的一行数据放在数组中,
while($row=mysqli_fetch_array($result))
{
echo "<tr>";
echo "<th scope='row'>" . $row['id'] . "</th>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['tent'] . "</td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
echo "</body>";
mysqli_close($con);
?>
sql.php
连接数据库
<?php
//连接数据库,主机,用户名,密码
$con = mysqli_connect("localhost","root","");
if (!$con) {
//如果连接不成功则报错
die("Connection failed: " . mysqli_connect_error());
}
echo "连接成功";
//打开指定的数据库
mysqli_select_db($con,"mydb");
//定义字符类型
mysqli_query($con,"SET names UTF8");
?>