我所做的是把所有這些
索引.php
<?php
include('includes/navbar.php');
?>
<!-- Main Content -->
<?php
include('includes/footer.php');
?>
頁面2.php
<?php
include('includes/navbar.php');
?>
<!-- Main Content -->
<?php
include('includes/footer.php');
?>
頁面3.php
<?php
include('includes/navbar.php');
?>
<!-- Main Content -->
<?php
include('includes/footer.php');
?>
第4頁.php
<?php
include('includes/navbar.php');
?>
<!-- Main Content -->
<?php
include('includes/footer.php');
?>
第5頁.php
<?php
include('includes/navbar.php');
?>
<!-- Main Content -->
<?php
include('includes/footer.php');
?>
code.php 這是驗證用戶是管理員用戶還是非管理員用戶的代碼 !password_verify 用于驗證密碼和哈希密碼。
if(isset($_POST['login_btn']))
{
$email_login = $_POST['emaill'];
$password_login = $_POST['passwordd'];
$query = "SELECT * FROM register WHERE email='$email_login' LIMIT 1";
$query_run = mysqli_query($connection, $query);
$password = "SELECT password FROM register WHERE email='$email_login'";
$usertypes = mysqli_fetch_array($query_run);
if($usertypes['usertype'] == "admin")
{
if(!password_verify($password_login, $password))
{
$_SESSION['username'] = $usertypes['username'];
header('Location: index.php');
}
else
{
$_SESSION['status'] = "Email / Password is Invalid";
header('Location: login.php');
}
}
else if ($usertypes['usertype'] == "user")
{
if(!password_verify($password_login, $password)){
$_SESSION['username'] = $usertypes['username'];
header('Location: index2.php');
}
else
{
$_SESSION['status'] = "Email / Password is Invalid";
header('Location: login.php');
}
}
}
UPDATE: I've already found a solution to the problem... Just put all the list items tag<li></li> inside this php elseif if you want to display a specific navbar list when an Admin user is logged in but want to hide them in a non-admin one.
<?php if($_SESSION['TYPE'] == 'admin'): ?>
<li class="nav-item">
<a class="nav-link" href="PageForAdmin.php">
<i class="fas fa-user" style="font-size: 20px;"></i>
<span>Page For Admin</span></a>
</li>
<?php endif; ?>
uj5u.com熱心網友回復:
使用if else回圈 For Laravel
@if(Auth::user()->user_role == "role")
// Show page 1
@else
// show page 2
@endif
為你
<?php
if ($user->role == 'admin'){
<li class="nav-item">
<a class="nav-link" href="page1.php">
<i class="fas fa-fw fa-tachometer-alt"></i>
<span>Page1</span></a>
</li>
}else {
<li class="nav-item">
<a class="nav-link" href="page.php">
<i class="fas fa-fw fa-tachometer-alt"></i>
<span>Page2</span></a>
</li>
}
?>
可能是代碼沒有編譯
<?php
if ($user->role == "admin"){
如果您使用數字,則
<?php
if ($user->role == 1){
注意:這是您可以使用的示例。我沒有測驗過。在條件下使用您想要的使用方式role或用戶型別if
<?php
if ($usertype->username == "admin){
5 頁示例
<?php
if ($user->role == 'admin'){
<li class="nav-item">
<a class="nav-link" href="page1.php">
<i class="fas fa-fw fa-tachometer-alt"></i>
<span>Page1</span></a>
</li>
}else if ($user->role == 'author'){
<li class="nav-item">
<a class="nav-link" href="page.php">
<i class="fas fa-fw fa-tachometer-alt"></i>
<span>Page2</span></a>
</li>
}else if ($user->role == 'editor'){
<li class="nav-item">
<a class="nav-link" href="page.php">
<i class="fas fa-fw fa-tachometer-alt"></i>
<span>Page3</span></a>
</li>
}else if ($user->role == 'superadmin'){
<li class="nav-item">
<a class="nav-link" href="page.php">
<i class="fas fa-fw fa-tachometer-alt"></i>
<span>Page4</span></a>
</li>
}else if ($user->role == 'superadmin2'){
<li class="nav-item">
<a class="nav-link" href="page.php">
<i class="fas fa-fw fa-tachometer-alt"></i>
<span>Page5</span></a>
</li>
}
?>
您可以使用嵌套if else或elseif也可以使用 next if in firstone's else like see below code
<?php
if ($user->role == 'admin'){
// your query
}else
if ($user->role == 'author'){
// your query
}else
if ($user->role == 'admin2'){
// your query
}else
if($user->role == 'admin1'){
// your query
}
}
?>
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/347469.html
標籤:php html css validation
上一篇:如何將預測結果中的集群ID轉換為R中k-means聚類預測模型中的類標簽?
下一篇:十進制數的Joi驗證無法正常作業
