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

 更新时间:2016年11月25日 17:34  点击:3049
这是注册程序是一款当用户输入完用户名是,就会自动去数据库中查询用户要注册的用户名是否己经被注册了,如果是返回提示否则提示可以注册。

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 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--]

相关文章

  • php 获取用户IP与IE信息程序

    php 获取用户IP与IE信息程序 function onlineip() { global $_SERVER; if(getenv('HTTP_CLIENT_IP')) { $onlineip = getenv('HTTP_CLIENT_IP');...2016-11-25
  • 不打开网页直接查看网站的源代码

      有一种方法,可以不打开网站而直接查看到这个网站的源代码..   这样可以有效地防止误入恶意网站...   在浏览器地址栏输入:   view-source:http://...2016-09-20
  • php 调用goolge地图代码

    <?php require('path.inc.php'); header('content-Type: text/html; charset=utf-8'); $borough_id = intval($_GET['id']); if(!$borough_id){ echo ' ...2016-11-25
  • JS+CSS实现分类动态选择及移动功能效果代码

    本文实例讲述了JS+CSS实现分类动态选择及移动功能效果代码。分享给大家供大家参考,具体如下:这是一个类似选项卡功能的选择插件,与普通的TAb区别是加入了动画效果,多用于商品类网站,用作商品分类功能,不过其它网站也可以用,...2015-10-21
  • JS实现自定义简单网页软键盘效果代码

    本文实例讲述了JS实现自定义简单网页软键盘效果。分享给大家供大家参考,具体如下:这是一款自定义的简单点的网页软键盘,没有使用任何控件,仅是为了练习JavaScript编写水平,安全性方面没有过多考虑,有顾虑的可以不用,目的是学...2015-11-08
  • JS基于Mootools实现的个性菜单效果代码

    本文实例讲述了JS基于Mootools实现的个性菜单效果代码。分享给大家供大家参考,具体如下:这里演示基于Mootools做的带动画的垂直型菜单,是一个初学者写的,用来学习Mootools的使用有帮助,下载时请注意要将外部引用的mootools...2015-10-23
  • php 取除连续空格与换行代码

    php 取除连续空格与换行代码,这些我们都用到str_replace与正则函数 第一种: $content=str_replace("n","",$content); echo $content; 第二种: $content=preg_replac...2016-11-25
  • php简单用户登陆程序代码

    php简单用户登陆程序代码 这些教程很对初学者来讲是很有用的哦,这款就下面这一点点代码了哦。 <center> <p>&nbsp;</p> <p>&nbsp;</p> <form name="form1...2016-11-25
  • PHP实现清除wordpress里恶意代码

    公司一些wordpress网站由于下载的插件存在恶意代码,导致整个服务器所有网站PHP文件都存在恶意代码,就写了个简单的脚本清除。恶意代码示例...2015-10-23
  • js识别uc浏览器的代码

    其实挺简单的就是if(navigator.userAgent.indexOf('UCBrowser') > -1) {alert("uc浏览器");}else{//不是uc浏览器执行的操作}如果想测试某个浏览器的特征可以通过如下方法获取JS获取浏览器信息 浏览器代码名称:navigator...2015-11-08
  • JS实现双击屏幕滚动效果代码

    本文实例讲述了JS实现双击屏幕滚动效果代码。分享给大家供大家参考,具体如下:这里演示双击滚屏效果代码的实现方法,不知道有觉得有用处的没,现在网上还有很多还在用这个特效的呢,代码分享给大家吧。运行效果截图如下:在线演...2015-10-30
  • JS日期加减,日期运算代码

    一、日期减去天数等于第二个日期function cc(dd,dadd){//可以加上错误处理var a = new Date(dd)a = a.valueOf()a = a - dadd * 24 * 60 * 60 * 1000a = new Date(a)alert(a.getFullYear() + "年" + (a.getMonth() +...2015-11-08
  • PHP开发微信支付的代码分享

    微信支付,即便交了保证金,你还是处理测试阶段,不能正式发布。必须到你通过程序测试提交订单、发货通知等数据到微信的系统中,才能申请发布。然后,因为在微信中是通过JS方式调用API,必须在微信后台设置支付授权目录,而且要到...2014-05-31
  • PHP常用的小程序代码段

    本文实例讲述了PHP常用的小程序代码段。分享给大家供大家参考,具体如下:1.计算两个时间的相差几天$startdate=strtotime("2009-12-09");$enddate=strtotime("2009-12-05");上面的php时间日期函数strtotime已经把字符串...2015-11-24
  • php根据用户语言跳转相应网页

    当来访者浏览器语言是中文就进入中文版面,国外的用户默认浏览器不是中文的就跳转英文页面。 <&#63;php $lan = substr(&#8194;$HTTP_ACCEPT_LANGUAGE,0,5); if ($lan == "zh-cn") print("<meta http-equiv='refresh' c...2015-11-08
  • php怎么用拼音 简单的php中文转拼音的实现代码

    小编分享了一段简单的php中文转拼音的实现代码,代码简单易懂,适合初学php的同学参考学习。 代码如下 复制代码 <?phpfunction Pinyin($_String...2017-07-06
  • php导出csv格式数据并将数字转换成文本的思路以及代码分享

    php导出csv格式数据实现:先定义一个字符串 存储内容,例如 $exportdata = '规则111,规则222,审222,规222,服2222,规则1,规则2,规则3,匹配字符,设置时间,有效期'."/n";然后对需要保存csv的数组进行foreach循环,例如复制代...2014-06-07
  • ecshop商品无限级分类代码

    ecshop商品无限级分类代码 function cat_options($spec_cat_id, $arr) { static $cat_options = array(); if (isset($cat_options[$spec_cat_id]))...2016-11-25
  • 几种延迟加载JS代码的方法加快网页的访问速度

    本文介绍了如何延迟javascript代码的加载,加快网页的访问速度。 当一个网站有很多js代码要加载,js代码放置的位置在一定程度上将会影像网页的加载速度,为了让我们的网页加载速度更快,本文总结了一下几个注意点...2013-10-13
  • php有效防止同一用户多次登录

    【问题描述】:同一用户在同一时间多次登录如果不能检测出来,是危险的。因为,你无法知道是否有其他用户在登录你的账户。如何禁止同一用户多次登录呢? 【解决方案】 (1) 每次登录,身份认证成功后,重新产生一个session_id。 s...2015-11-24