以下是我试图阻止用户访问我网站的代码。我正在使用MySQL数据库,并在我的用户表中插入禁止列并默认设置其值 1 ,告诉我我必须做什么。 MySQL数据库中此部分的表名是讲座所以请尽快帮助我。
<?php
session_start();
include("header.php");
include("conection.php");
//echo "lec name".$_SESSION["lecname"];
?>
<?php
if($banned == "1")
{
header("Location:lectureaccount.php");
}
else
{
header("Location:banned.php");
}?>
<?php
//if(isset($_SESSION["userid"]))
{
$lec_id = $_SESSION["userid"];
?>
答案 0 :(得分:0)
你做得很好。
我假设您需要知道SQL应该从数据库中获取用户数据。
<?php
session_start();
include("header.php");
include("conection.php");
//echo "lec name".$_SESSION["lecname"];
if(isset($_SESSION["userid"]))
{
$user_id = $_SESSION["userid"];
$con=mysqli_connect("example.com","username","password","database_name");
if (mysqli_connect_errno()){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT banned FROM Lectures where user_id = ".$user_id);
while($row = mysqli_fetch_array($result)){
$banned= $row['banned'];
}
mysqli_close($con);
if($banned == "1"){
header("Location:lectureaccount.php");
}
else{
header("Location:banned.php");
}
}
?>
<?php
//if(isset($_SESSION["userid"]))
{
$lec_id = $_SESSION["userid"];