用户名验证是否注册

以前研究过的 微软淘宝等网站的注册验证
CODE:


<!DOCTYPE html PUBLIC &#34;-//W3C//DTD XHTML 1.0 Transitional//EN&#34; &#34;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&#34;>

<html xmlns=&#34;http://www.w3.org/1999/xhtml&#34;>

<head>

<meta http-equiv=&#34;Content-Type&#34; content=&#34;text/html; charset=gb2312&#34; />

<title>UserCheck</title>

<script type=&#34;text/javascript&#34;>

function cr&#101;ateXMLHttpRequest(){

      if (window.ActiveXObject) {

              xmlHttp = new ActiveXObject (&#34;Microsoft.XMLHTTP&#34;);

      }

      else if (window.XMLHttpRequest) {

           xmlHttp = new XMLHttpRequest () ;

      }

}



function username(){

     cr&#101;ateXMLHttpRequest();

   var username = document.getElementById(&#34;username&#34;);

   var url = &#34;checkusername.php?username=&#34; + escape(username.value) + &#34;&ts=&#34; + new Date().getTime();

   xmlHttp.open(&#34;GET&#34;,url,true);

   xmlHttp.onreadystatechange = callback;

   xmlHttp.send(null);

  }



function callback(){

     if (xmlHttp.readyState==4){

       if (xmlHttp.status == 200) {

          var msg = xmlHttp.responseXML.getElementsByTagName(&#34;message&#34;)[0].firstChild.data;

        var val = xmlHttp.responseXML.getElementsByTagName(&#34;passed&#34;)[0].firstChild.data;

              setMessage(msg, val);

        }

    }

  }



function setMessage(message, color){

     var messageArea = document.getElementById(&#34;usermessage&#34;);

   var fontColor = &#34;red&#34;;

   var backColor = &#34;#FFC7C7&#34;;

   if (color == &#34;1&#34;) {

        fontColor = &#34;#2DAE1B&#34;;

      backColor = &#34;#CEFFC7&#34;;

    }

     messageArea.innerHTML = &#34;<table bgcolor=&#34; + backColor + &#34; width=&#34;100%&#34;><tr><td><font color=&#34; + fontColor + &#34;>&#34; + message + &#34;</font></td></tr></table>&#34;;

   }

   

</script>

</head>



<body>

<table width=&#34;580&#34; border=&#34;0&#34; cellspacing=&#34;0&#34; cellpadding=&#34;0&#34;>

  <tr>

    <td width=&#34;208&#34; height=&#34;42&#34;>UserName:

    <input name=&#34;username&#34; type=&#34;text&#34; size=&#34;16&#34; onchange=&#34;username();&#34;/></td>

    <td width=&#34;372&#34;><div id=&#34;usermessage&#34;></div></td>

  </tr>

</table>

</body>



</html>



CODE:


<? 

$hostname_web 
= &#34;&#34;;

$database_web = &#34;&#34;;

$username_web = &#34;&#34;;

$password_web = &#34;&#34;;

$web mysql_pconnect($hostname_web$username_web$password_webo&#114; trigger_error(mysql_error(),E_USER_ERROR); 



$user $_GET['username'];

mysql_sel&#101;ct_db($database_web, $web);

$query_user sprintf(&#34;Sel&#101;ct * FROM `userinfo` Wh&#101;re `username` = '%s'&#34;, $user);

$user mysql_query($query_user$webo&#114; die(mysql_error());

$row_user mysql_fetch_assoc($user);

$totalRows_user mysql_num_rows($user);



header(&#34;Content-type: application/xml&#34;);

echo &#34;<?xml version=&#34;1.0&#34; encoding=&#34;gb2312&#34;&#34;. &#34;?&#34;. &#34;>
&#34;;

echo &#34;<item>
&#34;;

echo &#34;    <message>
&#34;;

if ($totalRows_user 0) {

echo &
#34;Sorry!The username have been used! 
&#34;;

} elseif ($totalRows_user == 0) {

echo &
#34;The username have not been used! 
&#34;;

}

echo &
#34;</message>
&#34;;

echo &#34;    <passed>
&#34;;

if ($totalRows_user 0) {

echo &
#34;0&#34;;

} elseif ($totalRows_user == 0) { echo &#34;1&#34;; }

echo &#34;</passed>
&#34;;

echo &#34;</item>
&#34;;

?>

引用通告地址: http://www.anycc.com/blog/trackback.php?tbID=64&extra=0147d0
标签:  AJAX JavaScript
评论: 0 | 引用: 0 | 阅读: 1489
发表评论
昵 称: 密 码:
网 址: 邮 箱:
验证码: 验证码图片 选 项:
头 像:
内 容: