php用户注册登陆源码_php注册用户代码

hacker|
112

文章目录:

php网站登录注册源码

//login.php 负责处理用户登录与退出动作

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

exit('非法访问!');

}

$username = htmlspecialchars($_POST['username']);

$password = MD5($_POST['password']);

//包含数据库连接文件

include('conn.php');

//检测用户名及密码是否正确

$check_query = mysql_query("select uid from user where username='$username' and password='$password' limit 1");

if($result = mysql_fetch_array($check_query)){

//登录成功

$_SESSION['username'] = $username;

$_SESSION['userid'] = $result['uid'];

echo $username,' 欢迎你!进入 a href="my.php"用户中心/a

';

echo '点击此处 a href="login.php?action=logout"注销/a 登录!

';

exit;

} else {

exit('登录失败!点击此处 a href="javascript:history.back(-1);"返回/a 重试');

}

注:上述源码是在TP中的登录验证方法,供参考!!

求一用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 用户注册源码

html

head

title用户注册/title

/head

body

strong用户注册/strong

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

用户名称:input type="text" name="user"br

您的密码:input type="password" name="pass"br

确定密码:input type="password" name="pass2"br

input type="submit" name="submit" value="注册"

/form

/body

/html

?php

include ('conn.php'); //这里是您配置的数据库

if($_POST[submit]){

//判断用户名不低于字数

$struser=strlen($_POST[user]);

if($struser = 4){

echo "script language=javascriptalert('注册请输入5位数以上');history.go(-1);/script";

exit;

}

//判断用户是否存在

$users=$_POST[user];

$result=mysql_query("select * from manage where user='$users'");

$row=mysql_fetch_array($result);

if($_POST[user]==$row[user]){

echo "script language=javascriptalert('啊!这个名字有人注册啦!');history.go(-1);/script";

exit;

}

//判断用户密码两次输入正确

if($_POST[pass]!=$_POST[pass2]){

echo "script language=javascriptalert('亲,别耍我啦,两次密码怎么能输入不一样呢?');history.go(-1);/script";

exit;

}

$_POST[pass]=md5($_POST[pass]);

$sql=mysql_query("insert into manage(id,user,pass)

VALUES('','$_POST[user]','$_POST[pass]')

");

if($sql){

echo "script language=javascriptalert('亲,注册成功!');history.go(-1);/script";

}

else {

echo "script language=javascriptalert('对不起,亲!注册失败咯!');history.go(-1);/script";

}

exit;

}

mysql_close($con)

?

我自己写的 很简单,100%适合新人。加密了密码,利用的是MD5

1条大神的评论

  • avatar
    访客 2022-07-06 下午 09:44:47

    input type="submit" name="submit" value="注册"/form/body/html?php include ('conn.php

发表评论