用户注册检测用户名是否存在ajax+php代码
发布:smiling 来源: PHP粉丝网 添加日期:2014-08-15 14:06:26 浏览: 评论:0
在用户注册检测用户名是否存在我们要提供告诉用户你要注册的用户名是否可用,那么我们就得利用ajax技术来实例,下面是一款ajax php当用户输入完用户名时提示用户是否可用用的代码:
- <?php
- $title = isset($_get['title'])?$_get['title']:'';
- if( $title )
- {
- $sql ='select id from filecontent where title=''.$title.''';
- $q = mysql_query( $sql ) or die( mysql_error());
- if( mysql_num_rows( $q ) )
- {
- echo 1;
- }
- else
- {
- echo 0;
- }
- }
- else
- {
- echo 0;//开源代码phpfensi.com
- }
- ?>
- <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
- <html xmlns="http://www.111cn.net/1999/xhtml">
- <head>
- <meta http-equiv="content-type" content="text/html; charset=gb2312" />
- <title> 用户注册检测用户名是否存在ajax + php代码</title>
- <script>
- // 用户注册检测用户名是否存在ajax + php代码
- function createxmlhttprequest(){//创建xmlhttprequest对象
- if(window.activexobject){//ie
- try {
- return new activexobject("microsoft.xmlhttp");
- } catch(e){
- return;
- }
- }else if(window.xmlhttprequest){//mozilla,firefox
- try {
- return new xmlhttprequest();
- } catch(e){
- return;
- }
- }
- }
- function getrenews(value){//主调函数
- var xmlhttp=createxmlhttprequest();
- var url = "t.php?action=check&title="+value+"&mt="+math.random(300000);
- if (value==""){
- return false ;
- }
- if (xmlhttp){
- callback = getreadystatehandler(xmlhttp);
- xmlhttp.onreadystatechange = callback;
- xmlhttp.open("get", url,true);
- xmlhttp.send(null);
- }
- }
- //返回0代表用户名可用,否则提示己被注册。
- function getreadystatehandler(xmlhttp){//服务器返回后处理函数
- return function (){
- if(xmlhttp.readystate == 4){
- if(xmlhttp.status == 200){
- if (xmlhttp.responsetext==1){
- document.getelementbyid("checkid").innerhtml="<font color='red'>对不起,你输入的用户名己被注册!</font>";
- }else{
- document.getelementbyid("checkid").innerhtml="可以注册";
- }
- }
- }
- }
- }
- </script>
- </head>
- <body>
- 给input框增加onblur事件,当用户输入完用户名就检测用户名,并给出提示。
- 输入用户名<input name="title" type="text" id="title" size="40" onblur="getrenews(this.value);"><span id="checkid"></span>
- </body>
- </html>
Tags: 用户注册 ajax+php代码
- 上一篇:php 数字型转换成字符型方法
- 下一篇:php 数据库内容以数组形式保存文件中
相关文章
- ·php 用户注册实例代码,适合初学者(2013-12-11)
- ·Ajax用户注册验证(2013-12-16)
- ·php 用户注册并且设置为己登录状态实现方法(2014-09-11)
- ·php+ajax用户注册验证用户是否在存(2014-09-11)
- ·php+mysql实现用户注册登陆的方法(2021-05-05)
- ·php用户注册信息验证正则表达式(2021-06-26)
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)