创建首页代码 index.php
本页面加入了登录,注册,退出功能,并使用了session判断了用户是否登录
if($_SESSION['username']){
?>
退出
else{
?>
登录|注册
}
?>
以及销毁session
session_start();
if($_GET['act']=="loginout"){
$_SESSION['username']='';
?>
location.href="?";
exit;
}
index.php 完整代码<?php
session_start();
if($_GET['act']=="loginout"){
$_SESSION['username']='';
?>
location.href="?";
exit;
}
header("Content-type:text/html;charset=utf-8"); //设置编码
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "mybbs";
// 创建连接
$conn = mysqli_connect($servername, $username, $password, $dbname);
mysqli_set_charset($conn,'utf8'); //设定字符集
?>
html>
论坛.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;
}
if($_SESSION['username']){
?>
退出
else{
?>
登录|注册
}
?>
论坛列表[添加 ] | ||
主题 | 论坛 | 最后更新 |
$sql="select * from forums";
$que=mysqli_query($conn,$sql);
$sum=mysqli_num_rows($que);
if($sum>0) {
while ($row = mysqli_fetch_array($que)) {
?>
<?php echo $row['subject'] ?><?php echo ". $row["forum_description"] ?>
}
}else{
echo "
对不起,论坛正在建设中,感谢你的关注......";}
?>