首页 > 编程技术 > php

php ajax注册验证用户名是否存在代码

发布时间:2016-11-25 17:34

这是注册程序是一款当用户输入完用户名是,就会自动去数据库中查询用户要注册的用户名是否己经被注册了,如果是返回提示否则提示可以注册。

conn.php文件

 代码如下 复制代码

<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<script >
var xmlhttp
function showhint(str)
{
if (str.length==0)
  {
  document.getelementbyid("txthint").innerhtml=""
  return
  }
xmlhttp=getxmlhttpobject()
if (xmlhttp==null)
  {
  alert ("browser does not support http request")
  return
  }
xmlhttp.onreadystatechange=statechanged

var geturl="conn.php?q="+str
//sid是增加一个随机数 防止页面启用缓存技术·
geturl=geturl+"&sid="+math.random()
geturl=encodeuri(geturl);
geturl=encodeuri(geturl);
xmlhttp.open("get",geturl,true)
xmlhttp.send(null)
}
function statechanged()
{
if (xmlhttp.readystate==4 || xmlhttp.readystate=="complete")
 {
 document.getelementbyid("txthint").innerhtml=xmlhttp.responsetext
 }
}
function getxmlhttpobject()
{
var xmlhttp=null;
try
 {
 // firefox, opera 8.0+, safari
 xmlhttp=new xmlhttprequest();
 }
catch (e)
 {
 // internet explorer
 try
  {
  xmlhttp=new activexobject("msxml2.xmlhttp");
  }
 catch (e)
  {
  xmlhttp=new activexobject("microsoft.xmlhttp");
  }
 }
return xmlhttp;
}

</script>
</head>
<body bgcolor="#999999">
<center>
<form>
<table>
 <tr>
  <td>用户名:</td>
  <td><input type="text" id="txt1" onkeyup="showhint(this.value)"></td>
 </tr>
 <tr align="center">
  <td colspan="2"><span id="txthint"></span></td>
 </tr>
</table>
</form>
</center>
</body>
</html>

 

 代码如下 复制代码

<?php
$q=$_get["q"];
$q = urldecode($q);

if (strlen($q) > 0)
{
  $conn = @mysql教程_connect("localhost","root","1010") or die ("mysql连接错误");
  mysql_select_db("xin",$conn);
  mysql_query("set names 'utf8'");
  
  $sql = "select username from message where username = '$q'";
  $query = mysql_query($sql);
  @$row = mysql_fetch_array($query);
  
  if(!empty($row['username']))
  {
   $response = "<font color=red>已经被注册!</font>";
  }else
  {
   $response = "<font color=blue>恭喜!可以注册!</font>";
  }
  
  echo $response;
}

?>

数据库
drop database if exists `xin`;
create database `xin` /*!40100 default character set utf8 */;
use `xin`;


create table `message` (
  `id` int(11) not null auto_increment,
  `username` varchar(20) default null,
  primary key  (`id`)
) engine=innodb auto_increment=2 default charset=utf8 

//###########################################################
//
// for questions and comments
// roland (alias -=: vlieg :=-)
// icq #78354631
// mail: vlieg@atoomnet.net
//
// nb: this script won't work on free hosting pages, because of the secure mode!
// nb: you must have registered your icq# at http://web.icq.com/sms/login/ in order for this script to work
//###########################################################


$htmlreply="";
$post ="post http://web.icq.com/karma/dologin/1,,,00.html http/1.0
accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */*
referer: http://web.icq.com/sms/login/1,,,00.html
accept-language: nl
content-type: application/x-www-form-urlencoded
accept-encoding: gzip, deflate
user-agent: mozilla/4.0 (compatible; msie 5.0; windows 98; digext)
host: web.icq.com
content-length: ".$contentlength."
proxy-connection: keep-alive
pragma: no-cache
cookie: uin=".$uin."; sms_country=".$prefix."; karmaservice1=yes; uin=".$uin."; sms_country=".$prefix."; karmaservice1=yes

uservice=1&ulogin=".$uin."&upassword=".$passw."&x=0&y=0";

$remote = fsockopen("web.icq.com", 80, &$errno, &$errstr, 30);

global $remote;
global $post;
fputs($remote, $post);

while (!feof($remote)) { $htmlreply.=fgets($remote,120); }
//uncomment for output: echo "".htmlspecialchars($htmlreply)."";
fclose($remote);

//****************************************************************//persoonlijke cookie uit de inlogpage halen
// en: fetch personal cookie from login page

$splited = split(" ",$htmlreply);
$cookies = $splited[3];
$cookies = str_replace("set-cookie: karmalogin=","",$cookies);
$cookies = str_replace("; path=/","",$cookies);
$cookies = str_replace(" ","",$cookies);
//uncomment voor output: echo $cookies;

if (strlen($prefix) == 2) { $contentprefix = ' '.$prefix; } else { $contentprefix = $prefix; }
$charcount = (160-strlen($message));
$contentlength= ( 1561+
strlen($message)+
strlen($charcount)+
strlen($phonenumber)+
strlen($prefix)
);

//****************************************************************//verzendpagina openen met de opgehaalde cookie
// en: open send page with fetched cookie

$htmlreply="";
$post ='post http://web.icq.com/sms/send_history/1,,,00.html http/1.0
accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */*
referer: http://web.icq.com/sms/send_session/1,,,00.html?prefix=+'.$prefix.'&carrier=&tophone='.$phonenumber.'
accept-language: nl
content-type: multipart/form-data; boundary=---------------------------7d12442eab4
accept-encoding: gzip, deflate
user-agent: mozilla/4.0 (compatible; msie 5.0; windows 98; digext)
host: web.icq.com
content-length: '.$contentlength.'
proxy-connection: keep-alive
pragma: no-cache
cookie: uin='.$uin.'; sms_country='.$prefix.'; karmaservice1=yes; karmalogin='.$cookies.'; uin='.$uin.'; sms_country='.$prefix.'; karmaservice1=yes; karmalogin='.$cookies.'

-----------------------------7d12442eab4
content-disposition: form-data; name="carrier"


-----------------------------7d12442eab4
content-disposition: form-data; name="prefix"

'.$contentprefix.'
-----------------------------7d12442eab4
content-disposition: form-data; name="tophone"

'.$phonenumber.'
-----------------------------7d12442eab4
content-disposition: form-data; name="usession"

1
-----------------------------7d12442eab4
content-disposition: form-data; name="ureply"


-----------------------------7d12442eab4
content-disposition: form-data; name="ulastid"


-----------------------------7d12442eab4
content-disposition: form-data; name="usend"

1
-----------------------------7d12442eab4
content-disposition: form-data; name="unextid"


-----------------------------7d12442eab4
content-disposition: form-data; name="uhistorycounter"

1
-----------------------------7d12442eab4
content-disposition: form-data; name="count"

0
-----------------------------7d12442eab4
content-disposition: form-data; name="usubmitcount"

0
-----------------------------7d12442eab4
content-disposition: form-data; name="checknewmsg"

180000
-----------------------------7d12442eab4
content-disposition: form-data; name="charcount"

'.$charcount.'
-----------------------------7d12442eab4
content-disposition: form-data; name="msg"

'.$message.'
-----------------------------7d12442eab4
content-disposition: form-data; name="x"

30
-----------------------------7d12442eab4
content-disposition: form-data; name="y"

16
-----------------------------7d12442eab4--
';

$remote = fsockopen("web.icq.com", 80, &$errno, &$errstr, 30);

global $remote;
global $post;
fputs($remote, $post);

while (!feof($remote)) { $htmlreply.=fgets($remote,120); }
//uncomment for output: echo "".htmlspecialchars($htmlreply)."";
fclose($remote);

//****************************************************************// check if message is send if send 'moved permanently' is returned

if (eregi('moved permanently',$htmlreply))
{ echo "sms message successfully sent!"; }
else
{ echo "sms not sent!"; }

这是一款由php +txt文本文件做的在线调用投票系统,无需数据库支持可以完成在线用户调查功能。
 代码如下 复制代码
<html>
<head>
<title>在线调查程序代码</title>
</head>
<body>
<form method="post" action="survey.php教程">
  <p><input type="radio" value="0" name="vote">调查项目一</p>
  <p><input type="radio" name="vote" value="1">调查项目二</p>
  <p><input type="radio" name="vote" value="2">调查项目三</p>
  <p><input type="radio" name="vote" value="3">调查项目四</p>
  <p><input type="radio" name="vote" value="4">调查项目五</p>
  <p><input type="hidden" name="go"  value="1">
  <p><input type="submit" value="提交" name="b1"></p>
  <a href="www.111cn.net.php?result=1">查看结果</a>
</form>
</body>
</html>

//survey.php

<?

 代码如下 复制代码

/*
无需数据库教程在线投票调查php代码

*/
  $data="data.txt";
  $votes="survey.txt";
  $dataf=file($data);        /*读出调查项目文件中的项目*/
  $file_votes=fopen($votes, "r");
  $line_votes=fgets($file_votes, 255);  /*读出已经记录的调查结果*/
  fclose($file_votes);
  $single_vote=explode("|", $line_votes); /* 并将数据按指定的字串切开,再将字串传回到数组变量中  */
   if ($result!=1)         /*如果已经接受了调查*/
   {
    $file_votes=file($votes, "r");
    if ($remote_addr == $file_votes[1])                           /*检查是不是同一个人*/
      {
       echo "<center><font color=red>您已投过票了,谢谢您的参与!</font></center>";
       exit;
      }

    /*如果ip不重复,则执行以下程序*/
    $ficdest=fopen($votes, "w");
    for ($i=0; $i<=count($dataf)-1; $i++)
      {
         if ($i == $vote)
         {                                 /*判断选择了哪个项目*/
          $single_vote[$i]+=1;
         }
             fputs($ficdest, "$single_vote[$i]|"); /*将数据写回文件*/
      }
       fputs($ficdest, " $remote_addr");/* //写入投票者ip*/
    fclose($ficdest);
    $result=1; /*投票成功*/
  }

  /*写入投票结果后并显示投票结果*/
  if ($result==1)
  {
   echo "<table cellpadding=10>";
   for ($i=0; $i<=count($dataf)-1; $i++)
    {
     /*取得投票总数*/
     $tot_votes+=$single_vote[$i];
    }
   for ($i=0; $i<=count($dataf)-1; $i++)
    {
     $imag=strval($i).".gif";/*判断用哪种条形图片来显示统计结果*/
      $stat[$i]=$single_vote[$i]/$tot_votes*100;  /*计算百分比*/
     $scla=$stat[$i]*5;/*条形图和放大倍数,这里是安百分数的5倍的相素的宽度来显示的*/
     echo "<tr><td><li><font face=verdana size=2>";
     echo "$dataf[$i]</font></td><td align=left><font face=verdana size=2>";
     echo "<img" width=100% src="$imag" height=20 width=$scla align=middle>&nbsp;";/*输出条形码图*/
     printf("%.1f", "$stat[$i]");
     echo "%</font></td><td align=center><font face=verdana size=2>";
     /*输出本栏目投票数*/
     echo "$single_vote[$i]</font>";
     echo "</td></tr>";
   }
   echo "</table><p>";
   echo "<font face=verdana size=2>总投票数:$tot_votes </font>";
}

/*
data.txt 文件
调查项目一
调查项目二
调查项目三
调查项目四
调查项目五
*/
?>

非常简单的日历类

 代码如下 复制代码

date_default_timezone_set("etc/gmt-8");

class calendar{

var $t = array();
var $datesofmonth = array('1'=>'31','2'=>'28','3'=>'31','4'=>'30','5'=>'31','6'=>'30','7'=>'31','8'=>'31','9'=>'30','10'=>'31','11'=>'30','12'=>'31');
var $y,$m,$d;

function set($time){
$this->t = getdate($time);
$this->y = $this->t['year'];
$this->m = $this->t['mon'];
$this->d = date('d',$time);
}

function isrun(){
return ($this->y%400==0 || ($this->y%4==0 && $this->y%100==0)) ? 1 : 0;
}

function first(){
$time = mktime(0,0,0,$this->m,1,$this->y);
$time = getdate($time);
return $time['wday'];
}

function html(){
$isrun = $this->isrun();
$this->datesofmonth[2] = $isrun==1 ? 29: 28;
$html .= "<table style='border:solid 1px black;'> ";
$html .= "<tr><th><a href=''>上一月</a></th><th colspan='5'>{$this->y}年 {$this->m}月</th><th><a href=''>下一月</a></th><tr> ";
$html .= "<tr><td>星期天</td><td>星期一</td><td>星期二</td>111cn.net<td>星期三</td><td>星期四</td><td>星期五</td><td>星期六</td></tr> ";
$html .= "<tr> ";
$first = $this->first();
for($i=0; $i<$first; $i++){
$html .= "<td></td>";
}
$count = $this->datesofmonth[$this->m]+$first;
for ($i=1; $i<= $this->datesofmonth[$this->m]; $i++){
$style = $i==$this->d ? ' style="color:red;font-weight:bold;"' : '' ;
$html .= "<td align='center'{$style}>$i</td>";
if (($i==7%$first || ($i+$first)%7==0) && $i<$count){
$html .= "</tr> <tr>";
}
}
$count = 7-$count%7;
if ($count<7){
for ($i=0; $i<$count; $i++){
$html .= "<td></td>";
}
}
$html .= "</tr> ";
$html .= "</table> ";
return $html;
}
}

$calendar = new calendar();
$calendar->set(time());
echo $calendar->html();

本款手机号码归属地查询代码是一款php开源手机归属查询系统,本系统不依靠mysql之类的大型数据库,而是依靠文本,因为,一般一个手机号码,在查询系统中起决定作用的就是前7位
 代码如下 复制代码

if( $_post )
{
 $phone=(isset($_post["phone"]))?$_post["phone"]:die ("请返回");
echo "你查询的:$phone,资料:".getphone($phone);


function getphone($phone){
 $dbpath="datas/";
 $len=strlen($phone);
 if ( $len !=11 ){
 return "手机号码只支持11位";
 }
 $par="[0-9]";
 for ($i=0;$i<$len;$i++){
  if(!ereg($par,substr($phone,$i,1) ) ){
  return "手机号码只能为数字";
  }
 }
 $sunum=scandir($dbpath); //得到支持的手机号码前缀
  array_splice($sunum,0,1); //把当前目录取消
  array_splice($sunum,0,1); //把上一级目录去掉
 $sub=substr($phone,0,3); //取得该号码的前三位
 if (in_array($sub,$sunum) ){
   $num=substr($phone,3,4);
  $search=file($dbpath.$sub);
  $result=str_replace($num."=","",$search[$num]); //处理数据
  return (strlen($result)>1)?$result:"0";

 }else{
 return "暂不支持$sub";
 
 }

}
}
?>

 代码如下 复制代码

<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>手机号码归属地查询</title>
 </head>
<body>
 <form action="search.php" method="post">
 <p>请输入手机号码:<input type="text" name="phone"></p>
 <p><input type="submit" value="查询"></p></p>
 </form>
</body>
</html>

标签:[!--infotagslink--]

您可能感兴趣的文章: