php ajax用户注册检测代码

2008-07-03 16:54:36 北京时间

php ajax用户注册检测代码
index.php 复制PHP内容到剪贴板 PHP代码:<tr>
              <td width="25%" class="altbg1">&nbsp;&nbsp;用 户 名<font color="red">*</font><br /></td>
              <td>
                <input size="25" name="username" type="text" value="" onBlur="startRequest(document.getElementById('username').value);" />
              </td>
              <td id="ckuser"></td>
            </tr>
 
js:ajax.js 复制PHP内容到剪贴板 var xmlHttp;
    function createXMLHttpRequest()
    {
          if(window.XMLHttpRequest)
        {
              xmlHttp = new XMLHttpRequest();//mozilla浏览器
        }
        else if(window.ActiveXObject)
        {
            try
            {
             xmlHttp = new ActiveX0bject("Msxml2.XMLHTTP");//IE老版本
            }
            catch(e)
            {}
            try
            {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");//IE新版本
            }
            catch(e)
            {}
            if(!xmlHttp)
            {
                window.alert("不能创建XMLHttpRequest对象实例");
                return false;
            }
        }
    }
   
    php ajax用户注册检测代码
    function startRequest(username)
        {
            createXMLHttpRequest();//特编
           
            xmlHttp.open("GET","ckuser.php?name="+username,true);
            xmlHttp.onreadystatechange = handleStateChange;
            xmlHttp.send(null);
        }
       
       
    function handleStateChange()
    {
        if(xmlHttp.readyState==4)
        {
            if(xmlHttp.status==200)
            {
                //alert("来自服务器的响应:" + xmlHttp.responseText);
                if(xmlHttp.responseText == "true"){
                    document.getElementById("ckuser").innerHTML = '此用户名以被人注册';
                }
                else if(xmlHttp.responseText == "false")
                {
                    document.getElementById("ckuser").innerHTML = '检测通过';
                }
            }
        }
    }
 
ckuser.php   php ajax用户注册检测代码
PHP代码:
<?php
//
    //require_once "globals.php";
    require_once "config.inc.php";
    //require_once 'common/common.php';
    $username = $_GET["name"];
   
    $con = @mysql_connect("$dbserver","$dbuser","$dbpass" )or die("无法连接到数据库!");
    mysql_query("set names gbk");
    mysql_select_db("$dbname",$con)or die("无法选择数据库!");
   
    $query="select id from hj_member where username='".$username."';";
    $res=mysql_query($query);
        if(mysql_num_rows($res)!=0)
        {
             echo "true";
        }else
            {
               echo "false";
            }

?>




发表评论

请文明参与讨论,禁止漫骂攻击。本站保留不刊登无关和不雅评论的权力。


用户名: 密码: 匿名

相关新闻
echo $_SESSION[kfGid];//为0005 $kfGid = $rs[kfGid];//0001 ec
删除上传的图片及文件夹,主要的函数有file_exists(),unlink()
当然,前提要先打开CDN中一个功能reload_into_ims on.这样用户发
利用php的文件函数来实现上传 这段代码分为两个文件,一个为uplo
PHP默认的上传限定是最大2M,想上传超过此设定的文件,需要调整P

广告
© 2008 The Czz5 Company. All Rights Reserved. 关于我们 - 联系我们 - 广告业务 - 网站地图 - 版权声明 - 友情连接 - 网站投稿 - 致信编辑