亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Tutorial forum kecil pembangunan PHP laman utama kod lengkap

Buat indeks kod laman utama.php


Halaman ini telah menambah fungsi log masuk, pendaftaran dan keluar, dan menggunakan sesi untuk menentukan sama ada pengguna log masuk

<?php
jika ($_SESSION ['username']){
?>
<a href="?act=loginout">Keluar</a>
?<?php }
lain{
?>
<a href="login.html">Log Masuk</a>|<a href="reg.html">Daftar</a>
<? php
}
?>


dan musnahkan sesi

<?php
session_start();
if($_GET['act']=="loginout"){
$ _SESSION ['username']='';
?>
<script>
location.href="?";
</script>
<?
keluar;
}


index.php kod lengkap

<?php
session_start();
if($_GET['act']=="loginout"){
 $_SESSION['username']='';
 ?>
 <script>
        location.href="?";
    </script>
    <?
    exit;
}
header("Content-type:text/html;charset=utf-8");    //設(shè)置編碼
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "mybbs";
// 創(chuàng)建連接
$conn = mysqli_connect($servername, $username, $password, $dbname);
mysqli_set_charset($conn,'utf8'); //設(shè)定字符集
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>論壇</title>
    <style>
        .cen{
            width: 55%;
            margin: 0 auto;
            text-align: right;
            margin-top: 30px;
        }
        table{
            width: 55%;
            margin-top: 10px;
        }
        .title{
            background-color: #B10707;
            font-size: 17px;
            color: white;
        }
        .right{
            margin-left: 120px;
        }
    </style>
</head>
<body>
<div class="cen">
    <?php
    if($_SESSION['username']){
 ?>
 <a href="?act=loginout">退出</a>
    <?php }
 else{
 ?>
 <a href="login.html">登錄</a>|<a href="reg.html">注冊(cè)</a>
    <?php
 }
 ?>
</div>
<table border="1px" cellspacing="0" cellpadding="8"align="center">
    <tr class="title">
        <td COLSPAN="3">
            論壇列表<span class="right">[<a style="color: white" href="add_forum.php">添加</a> ]</span>
        </td>
    </tr>
    <tr>
        <td width="10%"><strong>主題</strong></td>
        <td width="40"><strong>論壇</strong></td>
        <td width="15"><strong>最后更新</strong></td>
    </tr>
    <?php
 $sql="select * from forums";
 $que=mysqli_query($conn,$sql);
 $sum=mysqli_num_rows($que);
 if($sum>0) {
 while ($row = mysqli_fetch_array($que)) {
 ?>
 <tr>
                <td><?php echo $row['subject'] ?></td>
                <td><?php echo "<div class=\"bold\"><a class=\"forum\" href=\"forums.php?F=" . $row['id'] . "\">" . $row["forum_name"] . "</a></div>"
 . $row["forum_description"] ?></td>
                <td>
                    <div><?php echo $row["last_post_time"]?></div>
                </td>
            </tr>
            <?php
 }
    }else{
 echo "<tr><td colspan='3'>對(duì)不起,論壇正在建設(shè)中,感謝你的關(guān)注......</td></tr>";
    }
 ?>
</table>
</body>
</html>


Meneruskan pembelajaran
||
<?php session_start(); if($_GET['act']=="loginout"){ $_SESSION['username']=''; ?> <script> location.href="?"; </script> <? exit; } header("Content-type:text/html;charset=utf-8"); //設(shè)置編碼 $servername = "localhost"; $username = "root"; $password = "root"; $dbname = "mybbs"; // 創(chuàng)建連接 $conn = mysqli_connect($servername, $username, $password, $dbname); mysqli_set_charset($conn,'utf8'); //設(shè)定字符集 ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>論壇</title> <style> .cen{ width: 55%; margin: 0 auto; text-align: right; margin-top: 30px; } table{ width: 55%; margin-top: 10px; } .title{ background-color: #B10707; font-size: 17px; color: white; } .right{ margin-left: 120px; } </style> </head> <body> <div class="cen"> <?php if($_SESSION['username']){ ?> <a href="?act=loginout">退出</a> <?php } else{ ?> <a href="login.html">登錄</a>|<a href="reg.html">注冊(cè)</a> <?php } ?> </div> <table border="1px" cellspacing="0" cellpadding="8"align="center"> <tr class="title"> <td COLSPAN="3"> 論壇列表<span class="right">[<a style="color: white" href="add_forum.php">添加</a> ]</span> </td> </tr> <tr> <td width="10%"><strong>主題</strong></td> <td width="40"><strong>論壇</strong></td> <td width="15"><strong>最后更新</strong></td> </tr> <?php $sql="select * from forums"; $que=mysqli_query($conn,$sql); $sum=mysqli_num_rows($que); if($sum>0) { while ($row = mysqli_fetch_array($que)) { ?> <tr> <td><?php echo $row['subject'] ?></td> <td><?php echo "<div class=\"bold\"><a class=\"forum\" href=\"forums.php?F=" . $row['id'] . "\">" . $row["forum_name"] . "</a></div>" . $row["forum_description"] ?></td> <td> <div><?php echo $row["last_post_time"]?></div> </td> </tr> <?php } }else{ echo "<tr><td colspan='3'>對(duì)不起,論壇正在建設(shè)中,感謝你的關(guān)注......</td></tr>"; } ?> </table> </body> </html>