完整phpajax用户注册与用户名验证实例_PHP教程
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了完整phpajax用户注册与用户名验证实例_PHP教程,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3709字,纯文字阅读大概需要6分钟。
内容图文
![完整phpajax用户注册与用户名验证实例_PHP教程](/upload/InfoBanner/zyjiaocheng/180/a44d1df310aa41efb0947d37932408e7.jpg)
checkusername.php文件
$username = $_get['username'];
mysql教程_connect('127.0.0.1', 'root', '') or die('could not connect: ' . mysql_error());
mysql_select_db('test');
//拼接sql语句时必须将用户输入的值做处理,替换特殊字符,用引号包含
$username = htmlentities($username,ent_quotes);
$sql = "select count(*) from user where username ='{$username}'";
$result = mysql_query($sql);
if($row = mysql_fetch_array($result, mysql_num)){
$cnt = $row[0];
if($cnt == 0) {
echo '用户名未被使用';
} else {
echo '用户名已被使用,请改换用户名';
}
}
?>
verifycode.php验证码程序
session_start();
$rnd = array_merge(range(0,9),range('a','z'));
shuffle($rnd);
$code = implode('',$rnd);
$code = substr($code,0,4);
$_session['verifycode'] = $code;
header("content-type: image/png");
$im = @imagecreate(50, 25) or die("cannot initialize new gd image stream");
$background_color = imagecolorallocate($im, 255, 255, 255);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 5, 5, 5, $code, $text_color);
imagepng($im);
imagedestroy($im);
?>
checkcode.php 检测用户输入的验证码是否一致
session_start();
$code = $_get['code'];
echo strtoupper($code) == $_session['verifycode'] ? '验证码正确' : '验证码错误';
?>
register.php注册处理程序
session_start();
$filename = '';
if(isset($_files['photo'])){
$uploaddir = dirname(__file__) . directory_separator . 'upload';
$originfilename = $_files['photo']['name'];
$extname = strtolower(substr($originfilename,strrpos($originfilename,'.')+1));
$filename = time() . '.' . $extname;
$validext = array('jpg','jpeg','gif','png');
if(!in_array($extname,$validext)){
errormsg("错误的文件类型");
}
if($_files['photo']['size'] > 100*1024){
errormsg("文件太大,超过了100k");
}
$uploadfile = $uploaddir . directory_separator . $filename;
if(!move_uploaded_file($_files['photo']['tmp_name'], $uploadfile)) {
errormsg("照片上传失败");
}
}
$code = $_post['verifycode'];
if($code != $_session['verifycode']){
errormsg("验证码输入不正确");
}
mysql_connect('127.0.0.1', 'root', '');
mysql_select_db('test');
mysql_query('set names utf8');
$username = addslashes($_post['username']);
$pwd = md5($_post['pwd']);
$name = addslashes($_post['name']);
$sex = addslashes($_post['sex']);
$age = intval($_post['age']);
$mobile = addslashes($_post['mobile']);
$address = addslashes($_post['address']);
$email = addslashes($_post['email']);
$photo = $filename;
$birthday = addslashes($_post['birthday']);
$sql = "insert into user(username,pwd,name,sex,age,mobile,address,email,photo,birthday)
values('$username','$pwd','$name','$sex',$age,'$mobile','$address','$email','$photo','$birthday')";
if(!mysql_query($sql)){
errormsg('数据库教程写入不成功!');
}
$sql = 'select * from user';
$res = mysql_query($sql);
echo '
用户名 | 姓名 | 性别 | 年龄 | 手机 | 通信地址 | 邮件地址 | 出生日期 |
{$row['username']} | {$row['name']} | {$row['sex']} | {$row['age']} | {$row['mobile']} | {$row['address']} | {$row['email']} | {$row['birthday']} |
function errormsg($str){
die('');
}
?>
最简单数据库结构
drop database if exists test;
create database test character set utf8 collate utf8_general_ci;
use test;
create table user(
username char(10) primary key
,pwd char(32) not null
,name char(10) not null
,sex char(1) not null
,mobile char(11)
,age smallint
,address varchar(50)
,email varchar(30)
,photo varchar(20)
,birthday date
);
http://down.bKjia.c0m/down/code/php/qitayuanma/2010/1220/22331.html
http://www.bkjia.com/PHPjc/631710.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/631710.htmlTechArticle!doctype html public -//w3c//dtd html 4.01 transitional//en http://www.w3.org/tr/html4/loose.dtd html head meta http-equiv=content-type content=text/html; charset=gb2312 titleinser...
内容总结
以上是互联网集市为您收集整理的完整phpajax用户注册与用户名验证实例_PHP教程全部内容,希望文章能够帮你解决完整phpajax用户注册与用户名验证实例_PHP教程所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。