PHP实现登录注册-LAMP示例

文章目录

  • 效果演示
  • login.html
  • login.php
  • register.php
  • 源码
  • 番外


基础的环境搭建参考:
Apache安装配置(Windows和Linux)-有手就行
PHP安装配置(Windows和Linux)-一篇就够了
PHP连接MySQL-踩坑总结

效果演示


网页:http://123.56.47.42/UIUE/login.html

PHP实现登录注册效果演示

PHP实现登录注册效果演示

login.html



<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录页title>
    <link href="favicon.ico" rel="shortcut icon" />
    <script type="text/javascript" src="js/jquery-3.4.1.min.js">script>
    <link type="text/css" href="css/animatemin.css" rel="stylesheet"/>
    <link type="text/css" href="bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="stylesheet"/>
    <link type="text/css" href="css/TGTool.css" rel="stylesheet"/>
    <link type="text/css" href="css/model.css" rel="stylesheet"/>
    <link type="text/css" href="css/verify.css" rel="stylesheet"/>
    <link type="text/css" href="css/login.css" rel="stylesheet"/>
    <script type="text/javascript" src="bootstrap-3.3.7-dist/js/bootstrap.min.js">script>
    <script type="text/javascript" src="js/verify.js">script>
    <script type="text/javascript" src="js/TGTool.js">script>
    <style type="text/css">body{
      background:url(images/loginBg.jpg);background-size: 100% 100%;}style>
head>
<body>

<div id="modal-container">
    <div class="modal-background">
        <div class="modal">
            <h4 class="modal-title" id="myModalLabel">用户注册h4>
            <form class="form-horizontal">
                <div class="modal-body">
                    <div class="form-group">
                        <label for="name_add_input"  class="col-md-3 control-label">用户名label>
                        <div class="col-md-9">
                            <input type="text" class="form-control" name="name" id="name_add_input" placeholder="name">
                            <span class="help-block">span>
                        div>
                    div>
                    <div class="form-group">
                        <label for="password_add_input"  class="col-md-3 control-label">密码label>
                        <div class="col-md-9">
                            <input type="password" class="form-control" name="password" id="password_add_input" placeholder="password">
                            <span class="help-block">span>
                        div>
                    div>
                    <div class="form-group">
                        <label for="password2_add_input"  class="col-md-3 control-label" style="padding:0px 0px">确认密码label>
                        <div class="col-md-9">
                            <input type="password" class="form-control" name="password2" id="password2_add_input" placeholder="password again">
                            <span class="help-block">span>
                        div>
                    div>

                div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-primary" id="user_save_btn">注册button>
                    <button type="reset" class="btn btn-reset">重置button>
                    <button type="button" class="btn btn-default" id="closeBtn">关闭button>
                div>
            form>
        div>
    div>
div>

<div id="container">
    
    <div class="col-md-4" style="font-size:30px">
	<span class="label label-warning">
		<span class="glyphicon glyphicon-time" aria-hidden="true">
		<span id="time"><script type="text/javascript"> showTime();script>span>
		span>
	span>
    div>
    
    <div class="col-md-6 col-md-offset-6" style="top:20px">
        <p style="font-size:75px;color: #e76f51;font-family: 楷体"><B> 宿心B>p>
    div>
    <div class="col-md-4 col-md-offset-6" style="top:20px">
        <I><p style="font-size:33px;color: #f4a261;font-family: 仿宋">天地之大,四海为家!p>I>
    div>
    
    
<h3 class="col-sm-5"><B>用户名:B>h3> <input type="text" class="form-control input-lg" id="user_login_name" name="loginid" placeholder="请输入用户名"/> div>
<h3 class="col-sm-4"><B>密码:B>h3> <input type="password" class="form-control input-lg" id="user_login_password" name="password" placeholder="请输入密码" /> div> <I><div class="form-group" id="mpanel1" style="font-size: 18px;color: #5e5e5e;margin-top: 35px">div>I> <div class="row">

插播反爬信息 )博主CSDN地址:https://wzlodq.blog.csdn.net/

login.php



error_reporting(0);
header("Content-Type: text/html;charset=utf-8");
//建立连接

$conn = mysqli_connect('localhost','root','改成你的密码');
if($conn){
     
    //数据库连接成功
    $select = mysqli_select_db($conn,"uiue");	//选择数据库
    if($select){
     
        //数据库选择成功
        $user = $_POST["username"];
        $pass = $_POST["password"];
        //sql语句
        $sql_select = "select id,pwd from user where id = '$user' and pwd = '$pass'";
        //设置编码
        mysqli_query($conn,'SET NAMES UTF8');
        //执行sql语句
        $ret = mysqli_query($conn,$sql_select);
        $row = mysqli_fetch_array($ret);
        //用户密码正确
        if($row!=null&&$row!=null&&$user == $row['id']&&$pass == $row['pwd']){
     
            echo 100;
        }else{
     
            echo 200;
        }
    }
    //关闭数据库
    mysqli_close($conn);
}else{
     
    //连接错误处理
    die('Could not connect:'.mysqli_error());
}

?>

register.php



error_reporting(0);
header("Content-Type: text/html;charset=utf-8");
//建立连接
$servername = "localhost";
$username = "root";
$password = "改成你的密码";

$conn = mysqli_connect($servername, $username, $password, 'uiue');
if($conn){
     
    //数据库连接成功
    $select = mysqli_select_db($conn,"uiue");		//选择数据库

    $user = $_POST["username"];
    $pass = $_POST["password"];

    mysqli_set_charset($conn,'utf8');	//设置编码
    //sql语句
    $sql_select = "select id from user where id = '$user'";
    //sql语句执行
    $result = mysqli_query($conn,$sql_select);
    //判断用户名是否已存在
    $num = mysqli_num_rows($result);
    if($num){
     
        //用户名已存在
        echo 200;
    }else{
     
        //用户名不存在
        $sql_insert = "insert into user(id,pwd) values('$user','$pass')";
        //插入数据
        $ret = mysqli_query($conn,$sql_insert);
        $row = mysqli_fetch_array($ret);
        echo 100;

    }
    //关闭数据库
    mysqli_close($conn);
}else{
     
    //连接错误处理
    die('Could not connect:'.mysqli_error($conn));
}
?>

源码


GitHub

PHP实现登录注册-LAMP示例_第1张图片

番外


最近事情越来越多了,比赛、实验、大作业、项目、考试,已经很难挤出时间写博客了,十一月产量也不高,但是我会更的(咕咕咕)。

PHP实现登录注册-LAMP示例_第2张图片

原创不易,请勿转载本不富裕的访问量雪上加霜
博主首页:https://wzlodq.blog.csdn.net/
微信公众号:唔仄lo咚锵
如果文章对你有帮助,记得一键三连❤

你可能感兴趣的:(PHP,php,lamp,mysql,ajax,apache)