最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
PHP+AJAX实时检查帐号是否被注册代码
时间:2022-06-24 16:57:16 编辑:袖梨 来源:一聚教程网
数据库部分:
CREATE TABLE `username_list` ( `id` int(11) NOT NULL auto_increment, `username` varchar(60) character set latin1 NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
js代码
XML/HTML Code
输入的字符大于等于4才会检测
check_username.php
include_once("conn.php");
//check we have username post var
if(isset($_POST["username"]))
{
//check if its ajax request, exit script if its not
if(!isset($_SERVER['HTTP_X_REQUESTED_WITH']) AND strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') {
die();
}
//trim and lowercase username
$username = strtolower(trim($_POST["username"]));
//sanitize username
$username = filter_var($username, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW|FILTER_FLAG_STRIP_HIGH);
//check username in db
$results = mysql_query("SELECT id FROM username_list WHERE username='$username'");
//return total count
$username_exist = mysql_num_rows($results); //total records
//if value is more than 0, username is not available
if($username_exist) {
die('');
}else{
die('');
}
//close db connection
}
?>
相关文章
- 游湖北app如何预约门票 03-20
- iphone14max重量是否为200g 03-20
- 189邮箱app如何更换头像 03-20
- 国际象棋小兵怎么吃子 03-20
- 北斗融媒app如何查看头条 03-20
- 猫眼电影账号如何注销 03-20