嗨,我正在創建一個基於用戶級別的導航系統。我所做的代碼沒有顯示任何錯誤,但沒有顯示菜單。我不知道我哪裏出錯了。我搜索這種菜單,但我找不到任何解決方案。任何人都可以排除我犯的錯誤嗎?或者告訴我是否還有其他方法可以做到這一點?基於用戶級別的導航菜單
這是我的代碼。
<html>
<head>
<title>Index</title>
</head>
<body>
<!--database connection-->
<?php
//error_reporting(0);
'session_start()';
$con = new mysqli('localhost', 'username', 'password', 'database');
if($con->connect_errno > 0){
die('Sorry, We\'re experiencing some connection problems.');
}
?>
<!--functions-->
<?php
function loggedin(){
if(isset($_SESSION['user_id'])){
return true;
}else{
return false;
}
}
?>
<!--titlebar-->
<div>
<?php
if(loggedin()){
$my_id=$_SESSION['user_id'];
$log=$con->prepare("SELECT username,user_level FROM users WHERE user_id='$my_id'");
$log->execute;
$log->bind_result($username, $user_level,$my_id);
$log->store_result;
if($log->fetch()) //fetching the contents of the row
{
if($user_level=='a'){?>
<a href = 'index.php'>Home</a>
<a href = 'admin.php'>Admin</a>
<a href = 'index.php'>Log Out</a>
<?php
}if($user_level=='m'){?>
<a href = 'index.php'>Home</a>
<a href = 'profile.php'>Profile</a>
<a href = 'index.php'>Log Out</a>
<?php
}else{?>
<a href = 'index.php'>Home</a>
<a href = 'login.php'>Login</a>
<a href = 'register.php'>Register</a>
<?php
}
}
}
?>
</div>
Index
</body>
</html>
我對我的登錄頁面使用了相同的方法,它工作正常。這是我的登錄頁面代碼。
<html>
<head>
<title>LOGIN</title>
</head>
<body>
<?php include 'connect.php';?>
<?php include 'functions.php';?>
<?php include 'titlebar.php';?>
<h3>LOGIN HERE:</h3>
<form action ="" method="post">
User Name:<br/>
<input type='text' name='username' />
<br/><br/>
Password:<br/>
<input type='password' name='password' />
<br/><br/>
<input type='submit' name='submit' value='login'>
</form>
<?php
if(isset($_POST['submit'])){
$username = $_POST['username'];
$password = md5($_POST['password']);
$stmt = $con->prepare("SELECT user_id, username, password, status FROM users WHERE username=? AND password=? LIMIT 1");
$stmt->bind_param('ss', $username, $password);
$stmt->execute();
$stmt->bind_result($user_id, $username, $password, $status);
$stmt->store_result();
if($stmt->num_rows == 1) //To check if the row exists
{
if($stmt->fetch()) //fetching the contents of the row
{
if ($status == 'd') {
echo "YOUR account has been DEACTIVATED.";
exit();
}
if ($status == 'b') {
echo "YOUR account has been BANNED.";
exit();
}
if ($status == 'n') {
echo "YOUR account has NOT YET BEEN ACTIVATED.";
exit();
}
else {
$_SESSION['Logged'] = 1;
$_SESSION['user_id'] = $user_id;
$_SESSION['username'] = $username;
echo 'Success!';
exit();
}
}
}
else {
echo "INVALID USERNAME/PASSWORD Combination!";
}
$stmt->close();
}
else
{
}
$con->close();
?>
</body>
</html>
任何幫助將是appartiated。
謝謝。
,我沒見過的loggedIn但反正它應該註冊和登錄菜單,但沒有顯示。並且該會話是一個排字錯誤 – Kishore
當然,它不會顯示任何菜單,因爲if(loggedin()){...}將永不會返回TRUE。如果我們談論工作登錄頁面,那麼你最好顯示包含文件的來源 – eh0t
那些包含文件在這個頁面上的第一個代碼部分 – Kishore