资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

php数据库用户注册页面,php注册页面登录代码

求一个最简单的PHP页面注册代码,数据库为MySQL

u_signup.htmhtml

创新互联公司是一家从事企业网站建设、做网站、网站制作、行业门户网站建设、网页设计制作的专业网站建设公司,拥有经验丰富的网站建设工程师和网页设计人员,具备各种规模与类型网站建设的实力,在网站建设领域树立了自己独特的设计风格。自公司成立以来曾独立设计制作的站点上千家。

head

/head

title欢迎注册网络图书销售信息管理系统/title

body

p align="center" class="style"会员注册/p

hr

form name="form1" method="post" action="u_signup.php"

p align="center"身份证号input name="u_sfzh" type="text" maxlength="18"/p

p align="center"会员姓名input name="u_hyxm" type="text" /p

p align="center"会员密码input name="u_hymm1" type="password" /p

p align="center"密码确认input name="u_hymm2" type="password" /p

p align="center"联系电话input name="u_lxdh" type="text" /p

p align="center"联系地址input name="u_lxdz" type="text" /p

p align="center"银行名称input name="u_yhmc" type="text" /p

p align="center"银行卡号input name="u_yhkh" type="text" /pp align="center"input name="u_return" type="submit" value="会员注册"/p

/form

/body

/html u_signup.php?php

//验证身份证号

$sfzh=$_POST['u_sfzh'];

if(empty($sfzh))

die("身份证号不能为空");

else if(strlen($sfzh)!=18)

die("身份证号应为18位");

else if(!is_numeric($sfzh))

die("身份证号应为18位数字");//验证会员姓名

$hyxm=$_POST['u_hyxm'];

if(empty($hyxm))

die("会员姓名不能为空");

else if(strlen($hyxm)4)

die("会员姓名应最少2个字符");

//验证会员密码

$hymm1=$_POST['u_hymm1'];

$hymm2=$_POST['u_hymm2'];

if(empty($hymm1) or empty($hymm2))

die("会员密码不能为空");

else if(strlen($hymm1)4 or strlen($hymm2)4 )

die("会员密码至少是4个字符");

else if($hymm1!=$hymm2)

die("两次输入的密码不一致");//验证联系电话

$lxdh=$_POST['u_lxdh'];

if(empty($lxdh))

die("联系电话不能为空");

else if(!is_numeric($lxdh))

die("联系电话应为数字");//验证联系地址

$lxdz=$_POST['u_lxdz'];

if(empty($lxdz))

die("联系地址不能为空");

else if(strlen($lxdz)6)

die("联系地址应最少6个字符");//验证银行名称和银行卡号

$yhmc=$_POST['u_yhmc'];

$yhkh=$_POST['u_yhkh'];

if(empty($yhmc) or empty($yhkh))

die("银行名称和银行卡号不能为空");

else if(strlen($yhmc)4 or strlen($yhkh)4 )

die("银行名称和银行卡号至少是4个字符");//获取系统日期和时间

$v_time=date("Y-m-d H:i:s");include "conn.php";mysql_query("set names 'GB2312'");//判断是否存在相同用户

//查询数据的sql语句形式:select * from member where 身份证号='123456789012345678'

$v_find="select * from member where 身份证号='".$sfzh."'";

//echo($v_find);

//echo("br");

$result=mysql_query($v_find,$conn);

$record=mysql_num_rows($result);

if($record0)

die($sfzh."该会员身份证号已经注册,不得重复,注册失败。");//注册用户

//插入数据的sql语句形式:insert into member values('11111111111111','1111',''...)

$v_insert="insert into member values('".$sfzh."','".$hyxm."','".$hymm1."','".$lxdh."','".$lxdz."','".$yhmc."','".$yhkh."','".$v_time."',0)";//echo($v_insert);

//echo("br");$result=mysql_query($v_insert);echo("注册成功");?conn.php?php

$host="localhost";

$user="root";

$password="123456";$conn=mysql_connect($host,$user,$password);

if(!$conn)

die("连接MySQL服务器失败。".mysql_error());$dbase="bookstore";

$db_select=mysql_select_db($dbase,$conn);

if(!$db_select)

die("连接MySQL数据库失败。".mysql_error());

?

php简单网站的登录和注册怎么写

注册:

用户名 :手机号或者邮箱

密码:规定6-16位字符或者6-12位,不能出现_、等字符,规定只能数字和英文字符组成

验证码:随机图片

ajax提交时验证用户名是否合法(邮箱或手机号验证)。去掉首尾空白。判断数据格式(过滤html标签,防止sql注入)

判断密码格式和长度

判断验证码正确

三者都正确。提交到后台处理:

查询用户名是否存在,如果存在,不能注册,返回页面。如果不存在则将密码加密处理(md5或者哈希加密生成一段密文,然后输入密码拼接生成的密文存入数据库更保险)

插入成功成功,返回登录界面。

登录:

和注册一样判断用户名。

提交到后台

后台可以用mysql_real_escape_string()函数对用户名和密码进行转义,防止sql注入

密码同样道理加密。去数据库查询用户名和密码,返回成功,则将用户id号和用户名存入session里。跳转页面。

求一用php写的注册和登录页面代码

reg.php文件

?php

header("Content-type:text/html;charset=utf-8");

if($_POST){

$dsn = 'mysql:dbname=1104javab;host=127.0.0.1';

$user = 'root';

$password = '';

try{

$pdo = new pdo($dsn,$user,$password,array(PDO::MYSQL_ATTR_INIT_COMMAND = 'SET NAMES \'UTF8\'')

);

}catch(Exception $e){

echo '错误'.$e-getmessage();

}

$name = $_POST['name'];

$pwd = md5($_POST['pwd']);

$sql = "insert into 表 (username,password) values ('$name','$pwd')";

$exec = $pdo-query($sql);

if($exec){

echo "scriptalert('成功');location.href='reg.html'/script";

}else{

echo "scriptalert('失败');location.href='reg.html'/script";

}

}

?

reg.html文件

form action='reg.php' method='post'

用户名:input type='text' name='name'

密码:input type='password' name='pwd'

input type='submit' value='submit'

/form

login.html文件

form action='reg.php' method='post'

用户名:input type='text' name='name'

密码:input type='password' name='pwd'

input type='submit' value='submit'

/form

login.php文件

header("Content-type:text/html;charset=utf-8");

if($_POST){

$dsn = 'mysql:dbname=1104javab;host=127.0.0.1';

$user = 'root';

$password = '';

try{

$pdo = new pdo($dsn,$user,$password,array(PDO::MYSQL_ATTR_INIT_COMMAND = 'SET NAMES \'UTF8\'')

);

}catch(Exception $e){

echo '错误'.$e-getmessage();

}

$name = $_POST['name'];

$pwd = $_POST['pwd'];

$sql = "select user_id from 表名 where username='$name' and password='$pwd'";

$stmt = $pdo-query($sql);

$info = $stmt-fetch(PDO::FETCH_ASSOC);

if($info){

echo "登录成功";

}else{

echo "登录失败";

}

}

大概这样

用PHP做登陆注册页面

登录页:login.php

?php

include("conn.php");

$username=$_POST['name'];

$password=$_POST['password'];

$yanzheng=$_POST['yanzheng'];

if(isset($_POST['submit']))

{

$sql=("select username,password from member where username='$username' and password='$password'") or die("sql语句执行失败");

//print_r($sql);

$ar=mysql_query($sql);

if($ar)

{

if($row=mysql_fetch_array($ar))

{

session_start();

if($_POST["yanzheng"])

{

if($yanzheng!=$_session[pic]||$yanzheng=="")

{

echo "验证码输入有误";

exit;

}

if($yanzheng==$_session[pic])

{

header("location:index.php");

}

}

}

else

{

echo "用户名或密码错误";

}

}

}

?

form action="login.php" method="post"

table border=1 align=center width=500 height=300 bgColor=#DFFFDF bordercolor=#fffbec

tr

td colspan=2 align=center用户登录/td

/tr

tr

td用户姓名:/td

tdinput type="text" name="name" id="name"//td

/tr

tr

td用户密码:/td

tdinput type="password" name="password" id="password"//td

/tr

tr

td验证码:/td

tdinput type="text" name="yanzheng" id="yanzheng"/

img src="yanzheng1.php" width="50" height="30"/img

/td

/tr

tr

td colspan=3 align=center

input type="submit" name="submit" value="登录"/

input type="reset" name="reset" value="重置"/

a href="register.php"注册/a

/td

/tr

/table

/form

注册页:register.php

?php

include("conn.php");

if(isset($_POST['submit'])$_POST['submit']) {

if($_POST['username']=='')

{

echo "用户名不能为空";

exit();

}

if($_POST['password']=='')

{

echo "密码不能为空";

exit();

}

if($_POST['realpass']!=$_POST['password'])

{

echo "两次密码输入不一致";

exit();

}

$sql="insert into member(username,real_name,password,email,headimg) values('$_POST[username]','$_POST[username]','$_POST[password]','$_POST[email]','')";

$ar=mysql_query($sql);

if($ar)

{

header("location:index.php");

}

else

{

echo mysql_error();

}

}

?

body

form action="register.php" method="post"

table border=1 align=center width=500

tr

td height=40 bgColor=#DFFFDF colspan=2会员注册 [a href="login.php"返回登录页/a]/td

/tr

tr

td height=40 bgColor=#fffbec 会员ID/td

tdinput type="text" name="username" id="username"//td

/tr

tr

td height=40 bgColor=#fffbec密码/td

tdinput type="password" name="password" id="password"//td

/tr

tr

td height=40 bgColor=#fffbec确认密码/td

td

input type="password" name="realpass" id="realpass"/

/td

/tr

tr

td height=40 bgColor=#fffbecEMAIL/td

tdinput type="text" name="email" id="email"/

/tr

tr

td height=40 bgColor=#fffbec/td

tdinput type="submit" name="submit" value="注册"/input type="reset" value="重置"/td

/tr

/table

/form

/body

主页显示:index.php

?php

include("conn.php");

function cutstr($str,$cutleng)

{

$str = $str; //要截取的字符串

$cutleng = $cutleng; //要截取的长度

$strleng = strlen($str); //字符串长度

if($cutleng$strleng)return $str;//字符串长度小于规定字数时,返回字符串本身

$notchinanum = 0; //初始不是汉字的字符数

for($i=0;$i$cutleng;$i++)

{

if(ord(substr($str,$i,1))=128)

{

$notchinanum++;

}

}

if(($cutleng%2==1)($notchinanum%2==0)) //如果要截取奇数个字符,所要截取长度范围内的字符必须含奇数个非汉字,否则截取的长度加一

{

$cutleng++;

}

if(($cutleng%2==0)($notchinanum%2==1)) //如果要截取偶数个字符,所要截取长度范围内的字符必须含偶数个非汉字,否则截取的长度加一

{

$cutleng++;

}

return substr($str,0,$cutleng);

}

?

html

head

script type="text/javascript"

function All(e, itemName)

{

var aa = document.getElementsByName(itemName);

for (var i=0; iaa.length; i++)

aa[i].checked = e.checked; //得到那个总控的复选框的选中状态

}

function Item(e, allName)

{

var all = document.getElementsByName(allName)[0];

if(!e.checked) all.checked = false;

else

{

var aa = document.getElementsByName(e.name);

for (var i=0; iaa.length; i++)

if(!aa[i].checked) return;

all.checked = true;

}

}

/script

/head

?php

include("conn.php");

if(isset($_POST['del']))

{

$mm = $_POST["selected"];

$id =implode(",",$mm);

$sql = "delete from forums where id in(".$id.")";

//echo $sql;

$result=mysql_query($sql);

echo $result?"删除成功":"删除失败";

}

?

table style="BORDER-BOTTOM-WIDTH: 1px; BORDER-COLLAPSE: collapse" cellSpacing=0 cellPadding=0 width=600 align=center border=1 bordercolor=#ddddff

tr align=middle

td height=40 bgColor=#DFFFDF colspan=3论坛列表/td

/tr

tr

td colspan=3a href="login.php" style="float:right"[退出系统]/aa href="add_forum.php" style="float:right"[添加论坛]/a/td

td/td

/tr

tr align=middle

td height=40 bgColor=#DFFFDF width=80状态/td

td height=40 bgColor=#DFFFDF论坛/td

td height=40 bgColor=#DFFFDF最后更新/td

/tr

?php

$sql="select * from forums";

$result=mysql_query($sql);

$num=mysql_num_rows($result);

if($num0)

{

while($row=mysql_fetch_array($result)){

?

tr align=middle

td bgColor=#fffbecinput type="checkbox" name="selected" value="1"//td

td height=50 bgColor=#fffbec width=300

?php

echo "diva href=\"forums.php?F=".$row['ID']."\"".$row['forum_name']."/a/div";

echo cutstr($row['forum_description'],24);//最多显示24个字节,12个字,多余部分用省略号代替

echo "……";

?

/td

td height=50 bgColor=#fffbecdiv?php echo $row['last_post_time']."by".$row['last_post_author']?/div/td

/tr

?php

}

}

else

{

echo "tr bgColor=#fffbectd colspan=3对不起,论坛尚在创建中……/td/tr";

}

?

tr

td colspan=3 input type="checkbox" name="selected" value="1" onclick="All(this,'selected')"/全选/不全选/td

/tr

tr

tdinput type="button" name="del" id="del" value="删除选中项"/

?php

?

/td

/tr

/table

/html

数据库你就自己建,望采纳~


当前文章:php数据库用户注册页面,php注册页面登录代码
本文地址:http://cdkjz.cn/article/dsssjes.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220