• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

php留言墙

武飞扬头像
进阶的小趴菜
帮助1

非常小白,大佬忽略。
🔎这里是【前端网页】,关注我学习前端不迷路
👍如果对你有帮助,给博主一个免费的点赞以示鼓励
欢迎各位🔎点赞👍评论收藏⭐️
👀专栏介绍
【php】 目前主要更新php,一起学习一起进步。
用php制作一款帖子发布支持登录注册内有不完美
仅供学习参考
勿喷
学新通
使用响应式制作适配移动 pc增加了限制直接访问跳转login注册在登录访问页面。

<?php
require_once './comm/config.php';
session_start();
if (!($_SESSION['loggedUsername'])){
    header("location:login.php");
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>留言墙</title>
    <link rel="stylesheet" href="./css/style.css">
    <link rel="stylesheet" href="./css/leaving.css">
</head>
<body>
    <div class="content">
        <canvas id="c" width="300" height="100vh"></canvas>  
        <div class="main">
            <p class="usernames">欢迎你!<?php echo $_SESSION['loggedUsername'];?><a href="loginout.php">退出</a></p>
            <div class="nav">
                <ul>
                    <li class="selected">留言墙</li>
                </ul>
            </div>
            <div class="content_tab">
                <div class="leaving item">
                    <div class="nav_tab">
                        <ul>
                            <li class="active" data-filter="all">全部</li>
                            <li data-filter="1">留言</li>
                            <li data-filter="2">目标</li>
                            <li data-filter="3">爱情</li>
                            <li data-filter="4">匿名</li>
                            <li data-filter="5">信条</li>
                        </ul>
                    </div>
                    <div class="tab_content">
                        <?php
                            $sql = "SELECT * FROM `liuyan` ORDER BY `liuyan`.`id` DESC";
                            $result = $conn->query($sql);
                            if($result->num_rows>0){
                                while($row = $result->fetch_assoc()){
                                ?>
                            <div class="items filtr-item" data-category="1">
                                <div class="box">
                                    <div class="header_card_boxs">
                                        <div><?php echo $row["time"];?></div>
                                        <div><?php echo $row["type"];?></div>
                                    </div>
                                    <div class="content_title">
                                        <?php echo $row["text"];?>
                                    </div>
                                    <div class="dz">
                                        <div class="left_box">
                                            <div class="icon">
                                                <svg t="1659140483353" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2304" width="200" height="200"><path d="M516.809433 921.67163S-142.389927 480.534026 144.538823 164.134706c18.112122-19.954032 40.522035-35.712601 65.592485-45.84311C335.278905 67.843709 429.932647 119.417208 478.026981 157.995003c20.568002 16.577196 50.038573 16.577196 70.606576 0C597.648846 118.700909 694.963126 65.797142 823.794544 121.259119c19.851704 8.595583 38.066154 20.670331 53.517737 35.814929C1183.78575 456.691516 516.809433 921.67163 516.809433 921.67163" p-id="2305" fill="#707070"></path></svg>
                                            </div>
                                            1
                                        </div>
                                        <div class="right_box">
                                            <?php echo $row["username"];?>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <?php
                            }
                        } else {
                            echo"暂无留言";
                        }
                        ?>
                        <?php
                            $sql = "SELECT * FROM `mb` ORDER BY `mb`.`id` DESC";
                            $result = $conn->query($sql);
                            $result = $conn->query($sql);
                            if($result->num_rows>0){
                                while($rows = $result->fetch_assoc()){
                                ?>
                            <div class="items filtr-item" data-category="2">
                                <div class="box">
                                    <div class="header_card_boxs">
                                        <div><?php echo $rows["time"];?></div>
                                        <div><?php echo $rows["type"];?></div>
                                    </div>
                                    <div class="content_title">
                                        <?php echo $rows["text"];?>
                                    </div>
                                    <div class="dz">
                                        <div class="left_box">
                                            <div class="icon">
                                                <svg t="1659140483353" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2304" width="200" height="200"><path d="M516.809433 921.67163S-142.389927 480.534026 144.538823 164.134706c18.112122-19.954032 40.522035-35.712601 65.592485-45.84311C335.278905 67.843709 429.932647 119.417208 478.026981 157.995003c20.568002 16.577196 50.038573 16.577196 70.606576 0C597.648846 118.700909 694.963126 65.797142 823.794544 121.259119c19.851704 8.595583 38.066154 20.670331 53.517737 35.814929C1183.78575 456.691516 516.809433 921.67163 516.809433 921.67163" p-id="2305" fill="#707070"></path></svg>
                                            </div>
                                            1
                                        </div>
                                        <div class="right_box">
                                            <?php echo $rows["username"];?>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <?php
                            }
                        } else {
                            echo"暂无留言";
                        }
                        ?>
                        <?php
                            $sql = "SELECT * FROM `love` ORDER BY `love`.`id` DESC";
                            $result = $conn->query($sql);
                            $result = $conn->query($sql);
                            if($result->num_rows>0){
                                while($love = $result->fetch_assoc()){
                                ?>
                                <div class="items filtr-item" data-category="3">
                                    <div class="box">
                                        <div class="header_card_boxs">
                                            <div><?php echo $love["time"];?></div>
                                            <div><?php echo $love["type"];?></div>
                                        </div>
                                        <div class="content_title">
                                            <?php echo $love["text"];?>
                                        </div>
                                        <div class="dz">
                                            <div class="left_box">
                                                <div class="icon">
                                                    <svg t="1659140483353" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2304" width="200" height="200"><path d="M516.809433 921.67163S-142.389927 480.534026 144.538823 164.134706c18.112122-19.954032 40.522035-35.712601 65.592485-45.84311C335.278905 67.843709 429.932647 119.417208 478.026981 157.995003c20.568002 16.577196 50.038573 16.577196 70.606576 0C597.648846 118.700909 694.963126 65.797142 823.794544 121.259119c19.851704 8.595583 38.066154 20.670331 53.517737 35.814929C1183.78575 456.691516 516.809433 921.67163 516.809433 921.67163" p-id="2305" fill="#707070"></path></svg>
                                                </div>
                                                1
                                            </div>
                                            <div class="right_box">
                                                <?php echo $love["username"];?>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <?php
                            }
                        } else {
                            echo"暂无留言";
                        }
                        ?>
                        <?php
                            $sql = "SELECT * FROM `nm` ORDER BY `nm`.`id` DESC";
                            $result = $conn->query($sql);
                            $result = $conn->query($sql);
                            if($result->num_rows>0){
                                while($nm = $result->fetch_assoc()){
                                ?>
                                <div class="items filtr-item" data-category="4">
                                    <div class="box">
                                        <div class="header_card_boxs">
                                            <div><?php echo $nm["time"];?></div>
                                            <div><?php echo $nm["type"];?></div>
                                        </div>
                                        <div class="content_title">
                                            <?php echo $nm["text"];?>
                                        </div>
                                        <div class="dz">
                                            <div class="left_box">
                                                <div class="icon">
                                                    <svg t="1659140483353" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2304" width="200" height="200"><path d="M516.809433 921.67163S-142.389927 480.534026 144.538823 164.134706c18.112122-19.954032 40.522035-35.712601 65.592485-45.84311C335.278905 67.843709 429.932647 119.417208 478.026981 157.995003c20.568002 16.577196 50.038573 16.577196 70.606576 0C597.648846 118.700909 694.963126 65.797142 823.794544 121.259119c19.851704 8.595583 38.066154 20.670331 53.517737 35.814929C1183.78575 456.691516 516.809433 921.67163 516.809433 921.67163" p-id="2305" fill="#707070"></path></svg>
                                                </div>
                                                1
                                            </div>
                                            <div class="right_box">
                                                匿名
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <?php
                            }
                        } else {
                            echo"暂无留言";
                        }
                        ?>
                        <?php
                            $sql = "SELECT * FROM `xt` ORDER BY `xt`.`id` DESC";
                            $result = $conn->query($sql);
                            $result = $conn->query($sql);
                            if($result->num_rows>0){
                                while($xt = $result->fetch_assoc()){
                                ?>
                                <div class="items filtr-item" data-category="5">
                                    <div class="box">
                                        <div class="header_card_boxs">
                                            <div><?php echo $xt["time"];?></div>
                                            <div><?php echo $xt["type"];?></div>
                                        </div>
                                        <div class="content_title">
                                            <?php echo $xt["text"];?>
                                        </div>
                                        <div class="dz">
                                            <div class="left_box">
                                                <div class="icon">
                                                    <svg t="1659140483353" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2304" width="200" height="200"><path d="M516.809433 921.67163S-142.389927 480.534026 144.538823 164.134706c18.112122-19.954032 40.522035-35.712601 65.592485-45.84311C335.278905 67.843709 429.932647 119.417208 478.026981 157.995003c20.568002 16.577196 50.038573 16.577196 70.606576 0C597.648846 118.700909 694.963126 65.797142 823.794544 121.259119c19.851704 8.595583 38.066154 20.670331 53.517737 35.814929C1183.78575 456.691516 516.809433 921.67163 516.809433 921.67163" p-id="2305" fill="#707070"></path></svg>
                                                </div>
                                                1
                                            </div>
                                            <div class="right_box">
                                                <?php echo $xt["username"];?>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <?php
                            }
                        } else {
                            echo"暂无留言";
                        }
                        ?>
                    </div>
                </div>
            </div>
            <div class="add_box" id="add">
                <svg t="1659166736274"  class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3781" width="200" height="200"><path d="M948.313043 442.991304l-369.530435 0 0-369.530435c0-37.843478-31.165217-69.008696-69.008696-69.008696-37.843478 0-69.008696 31.165217-69.008696 69.008696l0 369.530435-369.530435 0c-37.843478 0-69.008696 31.165217-69.008696 69.008696 0 37.843478 31.165217 69.008696 69.008696 69.008696l369.530435 0 0 369.530435c0 37.843478 31.165217 69.008696 69.008696 69.008696 37.843478 0 69.008696-31.165217 69.008696-69.008696l0-369.530435 369.530435 0c37.843478 0 69.008696-31.165217 69.008696-69.008696C1017.321739 474.156522 988.382609 442.991304 948.313043 442.991304z" p-id="3782" fill="#ffffff"></path></svg>
            </div>
            <div class="post_list" id="add_card">
                <div class="post_content">
                    <div class="closed">
                        <svg t="1659001949761" id="closes" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3311" width="200" height="200"><path d="M685.4 354.8c0-4.4-3.6-8-8-8l-66 0.3L512 465.6l-99.3-118.4-66.1-0.3c-4.4 0-8 3.5-8 8 0 1.9 0.7 3.7 1.9 5.2l130.1 155L340.5 670c-1.2 1.5-1.9 3.3-1.9 5.2 0 4.4 3.6 8 8 8l66.1-0.3L512 564.4l99.3 118.4 66 0.3c4.4 0 8-3.5 8-8 0-1.9-0.7-3.7-1.9-5.2L553.5 515l130.1-155c1.2-1.4 1.8-3.3 1.8-5.2z" p-id="3312" fill="#707070"></path><path d="M512 65C264.6 65 64 265.6 64 513s200.6 448 448 448 448-200.6 448-448S759.4 65 512 65z m0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372 372 166.6 372 372-166.6 372-372 372z" p-id="3313" fill="#707070"></path></svg>
                    </div>
                    <div class="mzsm_txt">
                        <h3>免责声明</h3>
                        <div class="title_text">
                            云安院是本人独自开发的,为便于与用户交流的留言平台。请不要利用此平台服务、制作、上传、下载、复制、发布、传播或者转载如下内容:
                        </div>
                        <div class="txt_box">
                            1、反对宪法所确定的基本原则的;
                            <br>
                            2、危害国家安全,泄露国家秘密,颠覆国家政权,破坏国家统一的;
                            <br>
                            3、榻害国家荣誉和利益的;
                            以及其他任何涉嫌违法的内容
                        </div>
                    </div>
                    <form action="manage/add.php" method="post">
                        <div class="tab_box">
                            <div class="nav_tabes">
                                <select name="select" id="">
                                     <option value="1">留言</option>
                                     <option value="2">目标</option>
                                     <option value="3">爱情</option>
                                     <option value="4">匿名</option>
                                     <option value="5">信条</option>
                                </select>
                            </div>
                        </div> 
                        <div class="inp_seac">
                            <div class="scanner_box">
                                <textarea name="content" id="tetx_b" onkeyup="cont(this)" maxlength="150" cols="30" rows="10" placeholder="请输入留言内容..."></textarea>
                                <div class="nums_boxs" id="numsss">
                                    0/150字
                                </div>
                                <!-- <div class="user_box">
                                    <input type="text" maxlength="10" placeholder="昵称">
                                </div> -->
                            </div>
                        </div>
                        <div class="sub_btn">
                            <input type="reset" value="丢弃">
                            <input type="submit" value="确定">
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <script src="./js/jquery.min.js"></script>
    <script src="./js/jquery.filterizr.js"></script>
    <script src="./js/leaving.js"></script>
</body>
</html>
学新通

应用了插件对card的留言卡进行筛选分类使用内置的响应式能够更好的适配响应
学新通

<?php
session_start();
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录</title>
    <link rel="stylesheet" href="./css/style.css">
    <link rel="stylesheet" href="./css/login.css">
    <script src="./js/login.js"></script>
    <link rel="stylesheet" href="./css/mead.css">
</head>
<body>
    <div class="login">
        <div class="login_box">
            <div class="left_box_list">
                <div class="logo_pic">
                    <div class="logo_pic_box">C</div>
                    <p class="">云安院留言墙</p>
                </div>
                <div class="left_tt">
                    <p class="title">智慧校园,创建无数可能</p>
                    <p class="bt">梦想创造未来,行动实现一切</p>
                    <p class="bt">不为明天只为现在的自己做出更好的成绩</p>
                    <div class="line"></div>
                    <div class="sc">重庆安全技术职业学院 &gt;</div>
                    <div class="bq"><a href="">@2022 重庆安全技术职业学院chuaner</a><br><a href="">京ICP证******号</a><a href=""> 隐私政策</a></div>
                </div>
            </div>
            <div class="right_box_btn">
                <h2>登录</h2>
                <form name="loginform" action="manage/doLogin.php" onSubmit="return check()" method="post">
                    <p>用户名</p>
                    <div class="user">
                        <input type="username" id="user" name="name" maxlength="10" placeholder="账号">
                        <br>
                        <span class="ts" id="tsyj"> </span>
                    </div>
                    <p>密码</p>
                    <div class="user">
                        <input type="password" name="pass" maxlength="16" minlength="6" placeholder="密码">
                        <br>
                        <span class="ts" id="tsyjs"> </span>
                    </div>
                    <div class="btn_reg">
                        <a class="reg" href="reg.php">还没有账号立即注册</a>
                    </div>
                    <div class="inp_btn">
                        <input type="submit" value="登录">
                    </div>
                </form>
                <div class="title_ts">
                    温馨提示:账号请勿转借以便造成不必要的损失
                </div>
            </div>
        </div>
        <div class="right_box">   
        </div>
    </div>
</body>
</html>
学新通

创建登录页将输入的限制增加在自定义的功能函数当中检测用户输入的信息进行检索定义的规范从而简略操作。
创建一个doLogin.php作为登录功能的实现

<?php
session_start();
?>
<?php
header("Content-Type:text/html;charset=utf-8");
$username = trim($_POST['name']);
$pw = trim($_POST['pass']);
if(!strlen($username) || !strlen($pw)){
    echo"<script>alert('用户名和密码必须填写');history.back();</script>";
    exit;
}
else{
    if(!preg_match('/^[a-zA-Z0-9]{3,10}$/',$username))
    {
        echo"<script>alert('用户名必填,且只能由大小写字符和数字构成,长度为3到10个字符!');history.back();</script>";
        exit; 
    }
    else{
        if(!preg_match('/^[a-zA-Z0-9\._]{6,20}$/',$pw))
        {
            echo"<script>alert('密码必填,且只能由大小写字符._和数字构成,长度为6到20个字符!');history.back();</script>";
            exit; 
        }
    }
}

include_once "../comm/config.php";
$sql = "SELECT * FROM `info` WHERE `username` = '$username' AND pw = '".md5($pw)."'";
$result = mysqli_query($conn,$sql);
$num = mysqli_num_rows($result);
if($num){
    $_SESSION['loggedUsername'] = $username;
    echo"<script>alert('登录成功');location.href='https://blog.csdn.net/qq_39459339/article/index.php';</script>";
    exit;
}
else{
    unset($_SESSION['loggedUsername']);
    echo"<script>alert('密码错误');history.back();</script>";
    exit;
}

学新通

其中注册跟登录页是一样的可以采用复制然后将其中的input的type为password复制一层将name值改为cpass其次就是将名称改为reg.php

<?php
header("Content-Type:text/html;charset=utf-8");
$username = trim($_POST['name']);
$pw = trim($_POST['pass']);
$cpw = trim($_POST['cpass']);

require_once '../comm/config.php';
session_start();
if(!strlen($username) || !strlen($pw)){
    echo"<script>alert('用户名和密码必须填写');history.back();</script>";
    exit;
}
else{
    if(!preg_match('/^[a-zA-Z0-9]{3,10}$/',$username))
    {
        echo"<script>alert('用户名必填,且只能由大小写字符和数字构成,长度为3到10个字符!');history.back();</script>";
        exit; 
    }
}
if($pw <> $cpw){
    echo"<script>alert('密码和确认密码必须相等');history.back();</script>";
    exit;
}
else{
    if(!preg_match('/^[a-zA-Z0-9\._]{6,20}$/',$pw))
    {
        echo"<script>alert('密码必填,且只能由大小写字符._和数字构成,长度为6到20个字符!');history.back();</script>";
        exit; 
    }
}
$sql = "SELECT * FROM `info` WHERE `username` = '$username'";
$result = mysqli_query($conn,$sql);
$num = mysqli_num_rows($result);
if($num){
    echo"<script>alert('用户名已被占用,请重新输入');history.back();</script>";
    exit;
}

$sql = "INSERT INTO `info` (`uid`, `username`, `pw`, `createtime`) VALUES (NULL, '$username', '".md5($pw)."', CURRENT_TIMESTAMP)";

$result = mysqli_query($conn,$sql);
if($result){
    echo"<script>alert('注册成功');location.href='https://blog.csdn.net/qq_39459339/article/login.php';</script>";
}
else{
    echo"<script>alert('注册失败');history.back();</script>";
}
学新通

在index当中的退出项还需要创建一个功能函数进行实现清楚登录产生的记录创建一个loginout.php

<?php
session_start();
session_destroy();
header("location:index.php");
?>

至于在发布的浮窗当中根据我们内定的几个发布选项去创建对应的sql即可,创建一个发布的功能函数add.php

<?php
require_once '../comm/config.php';
session_start();

if (!($_SESSION['loggedUsername'])){
    header("location:login.php");
}

$t = $_POST["t"];
$n = $_SESSION['loggedUsername'];
$time = date("Y-m-d H:i:s",time());

if($t && $n){
$sql = "INSERT INTO `liuyan` (`id`, `username`, `content`, `name`) VALUES (NULL, '$username', '$content', '$name');";
$conn->query($sql);
}
header("Location:index.php");
?>
学新通

创建链接数据库的功能php文件名称为comm.php和config.php
comm.php

<?php

   
    $sqlservername="localhost";
    $sqlusername="root";
    $sqlpassword="root";
    $sqldbname="liuyanban";
    
    $conn = new mysqli($sqlservername,$sqlusername,$sqlpassword,$sqldbname);
   
    if($conn->connect_error){
        die("连接失败:".$conn->connect_error);
    }
?>

config.php

<?php
require_once 'comm.php';
$title = "云安院留言墙";
?>

至此呢我们基本的所需要的功能就完成了这边呢点赞功能还没制作各位可以自己去制作一下,或者等本人闲下来去更新感谢支持!
有什么不懂得私信或者评论下方统一回复
不为盈利只为一起探讨学习

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgfckjf
系列文章
更多 icon
同类精品
更多 icon
继续加载