特定のページをデータベースの特定のグループにのみ表示できるようにしたい。私のSQLテーブルは次のように設定されています:
テーブル:DD_users列:id | グループ| ユーザー名| 言い換え| ギルド| レベル| 塩
これは私が使おうとしているコードです:
// First we execute our common code to connection to the database and start the session
require("common.php");
// At the top of the page we check to see whether the user is logged in or not
if(empty($_SESSION['user']))
{
// If they are not, we redirect them to the login page.
header("Location: /DD/index.php");
// Remember that this die statement is absolutely critical. Without it,
// people can view your members-only content without logging in.
die("Redirecting to /DD/index.php");
}
if($_SESSION['user']['group'] == '0')
{
// Destroy the session to make them log in again.
unset($_SESSION['user']);
// If they are not, we redirect them to the login page.
header("Location: /DD/index.php");
// Remember that this die statement is absolutely critical. Without it,
// people can view your members-only content without logging in.
die("Redirecting to /DD/index.php");
}
// Everything below this point in the file is secured by the login system
これを試してみると、グループ1と2のみにページへのアクセスを許可したい場合に、すべてのユーザーグループ(0、1、および2)にページへのアクセスを許可します。