注册表单
生成随机验证码功能的代码
<?php
function random_text($count, $rm_similar = false) {
$chars = array_flip(array_merge(range(0, 9), range('A', 'Z')));
if ($rm_similar) {
unset($chars[0], $chars[1], $chars[2], $chars['I'], $chars['O'], $chars['Z']);
}
for ($i = 0, $text = ""; $i < $count; $i++) {
$text .= array_rand($chars);
}
return $text;
}
?>
生成随机图形验证码功能的代码
<?PHP
include 'functions.php';
if (!isset($_SESSION)) {
session_start();
}
$width = 65;
$height = 20;
$image = imagecreate($width, $height);
$bg_color = imagecolorallocate($image, 0x33, 0x66, 0xff);
$text = random_text(5);
$font = 5;
$x = imagesx($image) / 2 - strlen($text) * imagefontwidth($font) / 2;
$y = imagesy($image) / 2 - imagefontheight($font) / 2;
$fg_color = imagecolorallocate($image, 0xff, 0xff, 0xff);
imagestring($image, $font, $x, $y, $text, $fg_color);
$_SESSION['captcha'] = $text;
ob_clean();
header('Content-type:image/png');
imagepng($image);
imagedestroy($image);
?>
注:建议使用360浏览器,低版本浏览器会让下载图片
生成随机图形验证码功能的截图
注册表单功能代码(带验证功能)
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<form method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>">
<table style="border: 1px solid red">
<tr>
<td>用户名</td>
<td><input type="text" name="nsurname" id="username"></td>
</tr
<tr>
<td>密码</td>
<td><input type="password" name="password1" id="password1" value=""></td>
</tr>
<tr>
<td>确认</td>
<td><input type="password" name="password2" id="password2" value=""></td>
</tr>
<tr>
<td>邮箱</td>
<td><input type="text" name="email" id="email"></td>
</tr>
<tr>
<td>验证</td>
<td><img src="captcha.php" alt=""/><br>
<input type="text" name="captcha" id="captcha"/></td>
</tr>
<tr>
<td colspan="2">
<input type="submit" name="submit" value="注册">
<a href="denglu.php">登录</a>
</td>
</tr>
</table>
<?php
if(!empty($_POST)){
if($nsurname==null){
echo "用户名不能为空";
}else{
if($password1!=$password2){
echo "两次密码输入不一致";
}else{
}
}
}
?>
</form>
</body>
</html>
注册表单功能截图
注册表单验证功能截图(带登录验证)
登录功能表单代码
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<form method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>">
<table style="border: 1px solid red">
<tr>
<td>用户名</td>
<td><input type="text" name="nsurname" id="username"></td>
</tr
<tr>
<td>密码</td>
<td><input type="password" name="password1" id="password1" value=""></td>
</tr>
<tr>
<td colspan="2">
<input type="submit" name="submit" value="登录">
<a href="newEmptyPHPWebPage.php">注册</a>
</td>
</tr>
</table>
<?php
if(!empty($_POST)){
if($nsurname==liuxiang&&$password1==liuxiang){
echo "登录成功,将在5秒后跳转!";
}else{
echo "登录失败";
}
}
?>
</form>
</form>
</body>
</html>
登录功能表单截图