我是PHP新手,我一直堅持這一點,所以任何幫助表示讚賞。PHP多用戶級別登錄頁面
在我的數據庫我有4個user_levels:
ID 名管理成員出納 unregistered_user
的問題是,當任何用戶登錄,它重定向它到頁面profile.php。 我需要爲每個用戶提供其他權限,搜索結果等。 我該如何做到這一點?
的login.php
<!doctype html>
<html>
<head>
<title>Login</title>
</head>
<body>
<?php include 'connect.php'; ?>
<?php include 'functions.php'; ?>
<?php include 'title_bar.php'; ?>
<h2>Login:</h2>
<form method='POST'>
<?php
if(isset($_POST['submit'])){
$username=$_POST['username'];
$password=$_POST['password'];
if(empty($username) or empty($password)){
echo "You missed something!";
}else{
$check_login=mysql_query("SELECT id, type FROM users WHERE username='$username' AND password='$password'");
if(mysql_num_rows($check_login)!=0){
$run=mysql_fetch_array($check_login);
$user_id=$run['id'];
$type=$run['type'];
if($type=='d'){
echo "<p>Account not activated!</p>";
}else{
$_SESSION['user_id']=$user_id;
header("location: profile.php");
}
}else{
echo "<p>Wrong information!</p>";
}
}
}
?>
<br/>
username:
<br/>
<input type='text' name='username'><br/>
<br/>
pass:
<br/>
<input type='password' name='password'><br />
<br><input type='submit' name='submit' value='Login'><br/>
</form>
</body>
</html>
session_start.php
<?php
session_start();
function loggedin(){
if(isset($_SESSION['user_id'])&& !empty($_SESSION['user_id'])){
return true;
}else{
return false;
}
}
?>
您需要張貼一些代碼才能獲得幫助。 – Mark 2014-11-04 15:34:04
請向我們顯示您的代碼。但正如我想的那樣,從用戶表中獲取用戶記錄,將權限設置爲$ _SESSION變量,並根據權限將其重定向到適當的頁面。 – vaso123 2014-11-04 15:34:45
你只是顯示/隱藏用戶不允許看到的東西.. – Naruto 2014-11-04 15:35:28