简易BBS

config.php


<?php
    header("Content-type: text/html; charset=utf-8");
    define('HOST','主机名');
    define('USERNAME','用户名');
    define('PASSWORD','密码');
    define('DBNAME','数据库名');
?>

connect.php


<?php 
    require_once('config.php');
    //连库
    if(!($con=mysql_connect(HOST,USERNAME,PASSWORD)))
    {
        echo mysql_error();
    }
    //选库
    if(!mysql_select_db(DBNAME))
    {
        echo mysql_error();
    }
    //字符集
    if(!mysql_query('set names utf8'))
    {
        echo mysql_error();
    }
?>

forum.php


<?php 
    require_once("usercheck.php");
    require_once("connect.php");
?>
<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <link rel="stylesheet" type="text/css" href="style.css">
        <script type="text/javascript" src="jquery-2.2.0.min.js"></script>
        <title>实验论坛</title>
    </head>
    <body>
        <table>
        <?php
            $sql="SELECT * FROM posts";
            $result=mysql_query($sql);
            $num=mysql_num_rows($result);
            for($i=$num;$i>0;$i--)
            {
                $row=mysql_fetch_assoc($result);
                echo "<tr>";
                echo "<p><a href=\"";
                echo "posts.php?pid=";
                echo $row['pid'];
                echo "\">";
                echo $row['title'];
                echo "</a></p></tr>";
            }
        ?>
        </table>
        <a href="putpost.php"><input type="button" class="button" style='margin:auto;' value="发表"></input></a>
    </body>
</html>

index.html


<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <link rel="stylesheet" type="text/css" href="style.css">
        <script type="text/javascript" src="jquery-2.2.0.min.js"></script>
        <title>实验论坛</title>
    </head>
    <body>
        <h1 style="text-align:center;">实验论坛</h1>
        <form style="text-align:center;" method="POST" action="login.php">
            <p><input name="username" type="text" class="text" placeholder="用户名"></input></p>
            <p><input name="password" type="password" class="text" placeholder="密码"></input></p>
            <p><input type="submit" class="button" value="登录"></input></p>
            <p><a href="register.html" class="graybutton">还没有账号?</a></p>
        </form>
    </body>
</html>

jquery-2.2.0.min.js文件请到jQuery官网下载


login.php


<?php 
    require_once('connect.php');
    $username=$_POST['username'];
    $password=md5($_POST['password']);
    $sql="select * from users where username='$username' and password='$password'";
    $result=mysql_query($sql);
    session_start();
    $_SESSION['username']=$username;
    if(!mysql_num_rows($result))
    {
        echo "<script>alert('用户名或密码错误!');";
        echo "window.history.back(-1);</script>"; 
        exit;
    }
    header("Location:forum.php");
?>

posts.php


<?php
    require_once("usercheck.php");
    require_once("connect.php");
    $pid=$_GET['pid'];
    $sql="SELECT * FROM posts WHERE pid='$pid'";
    $result=mysql_query($sql);
    $row=mysql_fetch_assoc($result);
?>
<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <link rel="stylesheet" type="text/css" href="style.css">
        <script type="text/javascript" src="jquery-2.2.0.min.js"></script>
        <title>帖子</title>
    </head>
    <body>
        <h1 style="text-align:center;"><?php echo $row['title']; ?></h1><br><br><br>
        <p><?php echo $row['content']; ?><p>
        <input type="button" value="回复"></input>
    </body>
</html>

putpost.php


<?php
    session_start();
    $username=$_SESSION['username'];
    if(!$username)
    {
        echo "<script>alert('你还没有登录!');";
        echo "window.location.href='index.html';</script>";
    }
?>
<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <link rel="stylesheet" type="text/css" href="style.css">
        <script type="text/javascript" src="jquery-2.2.0.min.js"></script>
        <title>发表帖子</title>
    </head>
    <body>
        <form style="text-align:center;" method="POST" action="putpost.handle.php">
            <p><input id="title" name="title" type="text" class="text" placeholder="标题" onblur="checktitle()"></input></p>
            <p><textarea name="content" rows="18" cols="100"></textarea></p>
            <p><input type="submit" class="button" value="发表"></input></p>
        </form>
    </body>
    <script type="text/javascript">
        function checktitle()
        {
            var title=document.getElementById("title");
            if(!title)
            {
                alert("标题不能为空!");
            }
        }
    </script>
</html>

putpost.handle.php


<?php
    require_once("connect.php");
    session_start();
    $username=$_SESSION['username'];
    if(!$username)
    {
        echo "<script>alert('你还没有登录!');";
        echo "window.location.href='index.html';</script>";
    }
    $title=$_POST['title'];
    $content=$_POST['content'];
    if(!$title)
    {
        echo "<script>alert('密码不能少于6位!');";
        echo "window.history.back(-1);</script>"; 
        exit;
    }
    $sql="INSERT posts(title,content) VALUES ('$title','$content')";
    mysql_query($sql);
    echo "<script>alert('发表成功!');";
    echo "window.location.href='forum.php'; </script>";
?>

register.html


<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <link rel="stylesheet" type="text/css" href="style.css">
        <script type="text/javascript" src="jquery-2.2.0.min.js"></script>
        <title>实验论坛注册</title>
    </head>
    <body>
        <h1 style="text-align:center;">新用户注册</h1>
        <form style="text-align:center;" method="POST" action="register.handle.php">
            <p><input name="username" id="username" type="text" class="text" placeholder="用户名" onblur="checkusername()"></input></p>
            <p><input name="password" id="password" type="password" class="text" placeholder="密码" onblur="checkpassword()"></input></p>
            <p><input type="submit" class="button" value="确认"></input></p>
            <p><a href="index.html" class="graybutton">返回</a></p>
        </form>
        <script type="text/javascript">
            function checkusername()
            {
                var username=document.getElementById("username").value;
                if(!username)
                {
                    alert ("用户名不能为空!");
                }
            }
            function checkpassword()
            {
                var password=document.getElementById("password").value;
                if(password.length<6)
                {
                    alert ("密码至少有6位!");
                }
            }
        </script>
    </body>
</html>

register.handle.php


<?php
    require_once("connect.php");
    session_start();
    $username=$_POST['username'];
    $password=md5($_POST['password']);
    if(!$username)
    {
        echo "<script>alert('用户名不能为空!');";
        echo "window.location.href='register.html';</script>";
        exit;
    }
    if(strlen($password)<6)
    {
        echo "<script>alert('密码不能少于6位!');";
        echo "window.location.href='register.html';</script>";
        exit;
    }
    if($username && strlen($password)>6)
    {
        $sql="SELECT * FROM users WHERE username='$username'";
        $result=mysql_query($sql);
        if(mysql_num_rows($result))
        {
            echo "<script>alert('用户名已经存在!');";
            echo "window.location.href='register.html';</script>";   
            exit;
        }
        $sql="INSERT users(username,password) VALUES ('$username','$password')";
        mysql_query($sql);
        echo "<script>alert('注册成功!');";
    }
    echo "window.location.href='index.html'; </script>";    
?>

style.css


body{
    font-family:YouYuan;
}
.bottom{
    color:#757575;
    position:absolute;
    bottom:0;
    width:100%;
    margin:0 auto;
    text-align:center;
}
.text{
    width:270px;
    height:42px;
    line-height:42px;
    margin-top:25px;
    padding:0 15px;
    background:#2d2d2d;
    background:rgba(45,45,45,.15);
    border-radius:6px;
    border:1px solid #3d3d3d;
    border:1px solid rgba(255,255,255,.15);
    box-shadow:0 2px 3px 0 rgba(0,0,0,.1) inset;
    font-family:YouYuan;
    font-size:16px;
    color:#ffffff;
    text-shadow:0 1px 2px rgba(0,0,0,.1);
    transition:all .2s;
}
.text:focus{
    outline:0;
    box-shadow:0 2px 3px 0 rgba(0,0,0,.1) inset,0 2px 7px 0 rgba(0,0,0,.2);
}
.button{
    transition: background-color 0.5s;
    background-color:#00bde7;
    border:0px solid #00bde7;
    border-radius:10px;
    cursor:pointer;
    color:#ffffff;
    font-family:YouYuan;
    font-size:18px;
    padding:11px 132px;
    text-decoration:none;
    white-space:nowrap;
}
.button:hover {
    background-color:#00aad1;
}

.garybutton{
    text-align:center;
    background-color:rgba(45,45,45,.15);
    padding:11px 96px;

    transition: background-color 0.5s;
    border:0px solid #00bde7;
    border-radius:10px;
    cursor:pointer;
    color:#ffffff;
    font-family:YouYuan;
    font-size:18px;
    text-decoration:none;
    white-space:nowrap;
}
.graybutton:hover{
    background-color:rgba(45,45,45,.45);
}

textarea{
    line-height:42px;
    margin-top:25px;
    padding:0 15px;
    background:#2d2d2d;
    background:rgba(45,45,45,.15);
    border-radius:6px;
    border:1px solid #3d3d3d;
    border:1px solid rgba(255,255,255,.15);
    box-shadow:0 2px 3px 0 rgba(0,0,0,.1) inset;
    font-family:YouYuan;
    font-size:16px;
    color:#ffffff;
    text-shadow:0 1px 2px rgba(0,0,0,.1);
    transition:all .2s;
}
textarea:focus{
    outline:0;
    box-shadow:0 2px 3px 0 rgba(0,0,0,.1) inset,0 2px 7px 0 rgba(0,0,0,.2);
}

usercheck.php


<?php
    session_start();
    $username=$_SESSION['username'];
    if(!$username)
    {
        echo "<script>alert('你还没有登录!');";
        echo "window.location.href='index.html';</script>";
    }
?>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值