首页 > 编程技术 > php

php 用户注册页面代码

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

这款用户注册程序是一款包括有数据库,注册页面,注册js 验证是一款完整理的php+mysql实用的用户注册代码。
 代码如下 复制代码

$conn=mysql_connect('localhost','root','root')or die('数据库连接错误');
mysql_select_db('demo',$conn);
mysql_query("set names 'gbk'");
//检测会员名称是否存在

if($_post[username]){

  $sql="select * from users where username='$_post[username]'";

  $res=mysql_query($sql)or die("查询失败!");
  $us=$_get[name];
  echo $us."222222";
  $ps教程= md5($_post[password]);
  $sex=$_post['sex'];
  $age=$_post['age'];
  $qq=$_post['qq'];
  $phone=$_post['phone'];
  $email=$_post['email'];
  $address=$_post['address'];
  if(is_array(mysql_fetch_row($res))){
       echo "该会员名已经存在!";
  }else{
        $sql="insert into users (username,password,sex,age,qq,phone,email,address) values ('$us','$ps',$sex,$age,$qq,'$phone','$email','$address')";
        echo $sql;
       mysql_query($sql)or die("注册失败");
       echo "<script>alert('注册成功');location.href='login.php'</script>";
  }
}
?>
<script language="网页特效" type="text/javascript">
function docheck(){

var username = document.regform.username.value;
var pwd =document.regform.password.value;
var repwd=document.regform.repassword.value;

if(username==""){
  alert("请输入用户名!");
    return false;
}
if(pwd==""){
  alert("请输入密码!");
    return false;
}
if(repwd != pwd){
  alert("两次填写的密码不相同!");
  return false;
}
}
</script>
<script language="javascript">
function createxmlhttprequest(){
 var xmlhttp;
 if(window.activexobject){
  xmlhttp = new activexobject("microsoft.xmlhttp");
 }else{
  xmlhttp = new xmlhttprequest();
 }
 //return xmlhttp;
}
function checkname(){

 var name = document.getelementbyid('username'); //获取用户名文本框
 var span = document.getelementbyid('name_info'); //获取用于显示结果的span标记
 if(name.value.length <= 4){
  span.style.color = '#ff0000'; //设置span标记内的字体颜色为红色
  span.innerhtml = '用户名长度不能少于4个字符!'; //span标记内容
  return false;
 }
 var xmlhttp = createxmlhttprequest();//创建异步请求对象
 var time = new date().gettime();
 var url = 'regval.php?name=' + name.value + '&tmp=' + time;//构造出请求地址
 xmlhttp.open("get",url,true); //建立一个异步请求
 //这里我们使用get方式请求
 xmlhttp.onreadystatechange = function(){ //监视请求状态
  span.style.color = '#ff9900';
  span.innerhtml = '查询中,请稍候!';

  if(xmlhttp.readystate == 4 && xmlhttp.status == 200){
alert(xmlhttp.responsetext+"........");
   if(xmlhttp.responsetext.indexof('no') != -1){ //如果服务器返回的信息中有no

    span.style.color = '#cb2121'; //设置span标记颜色为红色
    span.innerhtml = '用户名[' + name.value + ']已经被别的用户使用!';
    //document.regform.username.value="";
   }else{//如果返回信息中没有no

    span.style.color = '#00a800';//设置颜色为绿色
    span.innerhtml = '恭喜您,该用户名未被注册!';
   }
   return true;
   delete xmlhttp; //删除请求对象
  }
 }

 xmlhttp.send(null); //发送请求
}
</script>
  <form action="regval.php" method="post" onsubmit="return docheck()" name="regform">
  会员名称:
  <input type="text" name="username" value="" id="username" onblur="checkname()"/>
<span id="name_info"></span>
  <br>
  密&nbsp;&nbsp;&nbsp;&nbsp;码:
  <input type="password" name="password" value=""/><br>
  确认密码:
  <input type="password" name="repassword" value=""/><br>

性别:
男:<input name="sex" type="radio" value="0" checked="checked"/>
女:<input name="sex" type="radio" value="1"/><br>
年龄:<input type="text" name="age" value=""/><br>
qq:<input type="text" name="qq" value=""/><br>
电话:<input type="text" name="phone" value=""/><br>
email:<input type="text" name="email" value=""/><br>
地址:<input type="text" name="address" value=""/><br>
  <input type="submit" name="sub" value="注册"/>
  <input type="reset" name="re" value="取消"/>
  </form>

<?
/*

drop table if exists `users`;
create table `users` (
  `id` int(10) not null auto_increment,
  `username` varchar(50) not null,
  `password` varchar(50) not null,
  `sex` int(1) not null default '0',
  `age` int(10) not null,
  `qq` int(15) default null,
  `phone` varchar(50) default null,
  `email` varchar(50) default null,
  `address` varchar(100) default null,
  primary key (`id`)
) engine=innodb auto_increment=4 default charset=gbk;

-- ----------------------------
-- records of users
-- ----------------------------
insert into `users` values ('1', 'admin', '21232f297a57a5a743894a0e4a801fc3', '0', '22', '379559090', '666666', '666666@163.com', '武汉');
insert into `users` values ('2', 'root', '63a9f0ea7bb98050796b649e85481845', '0', '20', '1244249796', '8888888', '8888888@163.com', '中国');
insert into `users` values ('3', 'www.111cn.net', '96e79218965eb72c92a549dd5a330112', '0', '20', '1244249796', '8888888', '8888888@163.com', '中国');


本教程下载地址

http://down.111cn.net/down/code/php/xinwenxitong/2010/0812/20183.html

 代码如下 复制代码
class ajaxpage{
var $result;
 var $anchors;
 var $total;
 var $db;
 var $网页特效p/jsp.html target=_blank >jsp教程agination;
 function __construct($qry,$starting,$recpage,$jspagination)
 {  
     $this->db   =   &$globals['db'];
  $this->jspagination =  $jspagination;
  $rst  = $this->db->query($qry);
  $numrows = $this->db->num_rows;
  $qry   .= " limit $starting, $recpage";
  
  $this->result = $this->db->get_results($qry,array_a);
  
  $next  = $starting+$recpage;//the number next time end
  //$var  = ((intval($numrows/$recpage))-1)*$recpage;
  $page_showing = intval($starting/$recpage)+1;//the str shows on the page bar
  $total_page = ceil($numrows/$recpage); //total page
  if($numrows % $recpage != 0){
   $last = ((intval($numrows/$recpage)))*$recpage;
  }else{
   $last = ((intval($numrows/$recpage))-1)*$recpage;
  }
  $previous = $starting-$recpage;
  $anc = "<ul id='pagination-flickr'>";
  if($previous < 0){
   $anc .= "<li class='previous-off'>first</li>";
   $anc .= "<li class='previous-off'>previous</li>";
  }else{
   $anc .= "<li class='next'><a href='网页特效:$this->jspagination(0);'>first </a></li>";
   $anc .= "<li class='next'><a href='javascript:$this->jspagination($previous);'>previous </a></li>";
  }
  
  ################if you dont want the numbers just comment this block############### 
  
  $norepeat = 3;//no of pages showing in the left and right side of the current page in the anchors
  $j = 1;
  $anch = "";
  for($i=$page_showing; $i>1; $i--){
   $fpreviouspage = $i-1;
   $page = ceil($fpreviouspage*$recpage)-$recpage;
   $anch = "<li><a href='javascript:$this->jspagination($page);'>$fpreviouspage </a></li>".$anch;
   if($j == $norepeat) break;
   $j++;
  }
  $anc .= $anch;
  $anc .= "<li class='active'>".$page_showing."</li>";
  $j = 1;
  for($i=$page_showing; $i<$total_page; $i++){
   $fnextpage = $i+1;
   $page = ceil($fnextpage*$recpage)-$recpage;
   $anc .= "<li><a href='javascript:$this->jspagination($page);'>$fnextpage</a></li>";
   if($j==$norepeat) break;
   $j++;
  }
  
  ############################################################
  if($next >= $numrows){
   $anc .= "<li class='previous-off'>next</li>";
   $anc .= "<li class='previous-off'>last</li>";
  }else{
   $anc .= "<li class='next'><a href='javascript:$this->jspagination($next);'>next </a></li>";
   $anc .= "<li class='next'><a href='javascript:$this->jspagination($last);'>last</a></li>";
  }
   $anc .= "</ul>";
  $this->anchors = $anc;
  
  $this->totalstr = "page : $page_showing <i> of  </i> $total_page . total records found: $numrows";
 }
}

 

 代码如下 复制代码

mysql教程_connect('localhost','0731-cn','0731licheng1') or die('sever ');
 mysql_select_db('0731-cn') or die('database error');
 $sql = "select uid from member ";
 $query = mysql_query( $sql ) or die('ddd');
 while( $row = mysql_fetch_array( $query ) )
 {
  mysql_query("insert into uc_memberfields(uid,username,password,email,myid,myidkey,regip,regdate,lastloginip,lastlogintime  salt,secques) values('".$row['uid']."','".$row['uid']."')") or die('jjjjj'.mysql_error());

 }


 echo "全部导入";

本文章来讲二种读取文本文件并显示在网页的php实例了,方法很简单,用fopen,加explode,for就实现了。
 代码如下 复制代码
$file = "./text.txt";
$text = fread(fopen($file,"r"),filesize($file));
$line = explode(" ",$text);
echo "<table width=300 border=1 cellspacing=0 cellpadding=0>";
    for($i = 0; $i <= count($line); $i++){
 $txt = explode(" ",$line[$i]);
 echo "<tr><td>".$txt[0]."</td><td>".$txt[1]."</td><td>".$txt[2]."</td><td>".$txt[3]."</td></tr>";
    }
echo "</table>";

//方法二

 代码如下 复制代码

$content = file_get_contents('test.txt');

$arr = explode(" ", $content);
echo "<table>";

foreach ($arr as $v) {
$tmp = explode("    ", $v);
echo "<tr>";
echo "<td>" . $tmp[0] . "</td>";
echo "<td>" . $tmp[1] . "</td>";
echo "<td>" . $tmp[2] . "</td>";
echo "<td>" . $tmp[3] . "</td>";
echo "</tr>";
unset($tmp);
}

echo "</table>";

//其实不有一个方法来实现上的实例,file函数哦,这个我也不说多了。查查就知道了,它读出内容直接保存到数据,就不用我们使用explode函数了。
/*
文本文本格式如下

读取一个文本文件内容如下
1       aaaa    bbba    ccca
2       aaaa    bbbb    cccb
3       aaaa    bbbc    cccc
3       aaaa    bbbc    cccc

 

这是一款利用mysql php实例的用户注册代码,比较简单,就是把html提交过来的数据保存到mysql数据库。

 include('global.php');

 代码如下 复制代码

 if($_post['sub']){
  $user  = $_post['username'];
  $pwd   = md5($_post['password1'].$user);
  $email = $_post['email'];
   $q = $mysql->query("insert into `hl`.`hl_member`(`id`,`username`,`password`,`email`)values (null,'$user','$pwd','$email');");
  if($q){
   setcookie('login',$user);
   $prompt_msg->p('恭喜您,亲爱的会员,您已经注册成功!','index.php','现在去首页。','http://www.111cn.net','先去论坛逛逛!');
  }else{
   $prompt_msg->p('非常抱歉,系统发生故障!');
  }
 }
?>

<!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></title>
<link rel="stylesheet" type="text/css教程" href="css/reg_log.css" />

</head>

<body>
<form id="myform" name="myform" method="post" action="register.php">
<div id="top">注册&nbsp;<a href="login.php">登录</a></div>
<div id="content">
 <div class="c1">请填写以下必填信息完成注册</div>
    <div class="c2"><span>带红色*的都是必填项目,若填写不全将无法注册</span></div>
    <div class="cinput"><dl>
     <dt>用户名<font color="red">*</font></dt>
        <dd><input id="username" name="username" type="text" maxlength="12" /></dd>
        <dd id="user_prompt" class="prompt">大小写英文字母、汉字、数字、下划线组成的长度 3-12 个字节以内</dd>
    </dl></div>
    <div class="cinput"><dl>
     <dt>密&nbsp;&nbsp;码<font color="red">*</font></dt>
        <dd><input id="password1" name="password1" type="password" maxlength="16" /></dd>
        <dd id="pwd1_prompt" class="prompt">最小长度:6 最大长度:16,仅限字母、数字及_,字母区分大小写</dd>
    </dl></div>         
    <!--检测密码强度-->
 <div class="cinput" style="padding-bottom:0px;"><!--ie6 hack-->
     <div class="chkpwd">
         <span id="cp1_prompt" class="cp1"></span><span id="cp2_prompt" class="cp2"></span>
            <span id="cp3_prompt" class="cp3"></span>
     </div>
    </div>
    <div class="cinput" style="padding-top:0px;"><dl>
     <dt>确认密码<font color="red">*</font></dt>
        <dd><input id="password2" name="password2" type="password" maxlength="16" /></dd>
        <dd id="pwd2_prompt" class="prompt">请再输入一遍您上面填写的密码</dd>
    </dl></div>
    <div class="cinput"><dl>
     <dt>email<font color="red">*</font></dt>
        <dd><input id="email" name="email" type="text" /></dd>
        <dd id="email_prompt" class="prompt">请填写真实并且最常用的邮箱</dd>
    </dl></div>
    <div style="clear:both"></div>
</div>
<div id="bottom">
 <input class="btn1" type="submit" name="sub" value="提交注册" id="checkall" />
 <input class="btn2" type="reset" name="reset" value="重置" onclick="return sub(this.form)" />
</div>
</form>
</body>
</html>

数据库结构

 create table `hl`.`hl_member` (
`id` int( 4 ) not null auto_increment comment '自动编码',
`username` varchar( 100 ) not null comment '用户名称',
`password` varchar( 200 ) not null comment '用户密码',
`answer` varchar( 100 ) not null comment '密保答案',
`question` varchar( 100 ) not null comment '密保问题',
`email` varchar( 100 ) not null comment 'email',
`realname` varchar( 200 ) not null comment '登录限制',
`birthday` date not null comment '出生日期',
`telephone` varchar( 20 ) not null comment '电话号码',
`qq` varchar( 15 ) not null comment 'qq号码',
`count` int( 1 ) not null comment '登录限制',
`active` int( 1 ) not null comment '是否激活',
primary key ( `id` )
) engine = innodb character set gb2312 collate gb2312_chinese_ci;

标签:[!--infotagslink--]

您可能感兴趣的文章: