如何根据php中的会话显示菜单?

时间:2017-04-06 15:43:18

标签: php mysql session

  

我有2个表admin和superadmin。我有两个相同的登录页面   用户。我可以根据query.i为两者创建会话   用户。每个表都有列名roleID。对于superadmin roleID是   1,对于admin roleID是2.下面是我登录的代码,其中i   创建会话。我使用了1*((CUBL>1)*((DIFL>1)*1)) -> 1*((1500>1)*((0>1)*1)) 1*((1500>1)*((0>1)*1)) -> 1*(1*(0*1)) 1*(1*(0*1)) -> 1*(1*0) 1*(1*0) -> 1*0 = 0 ,我的会话正在运行。下边是   我的登录页面代码。

print_r
  

现在在home.php上我有一些菜单可以根据roleID来显示   菜单代码。

if (isset($_REQUEST['submit'])) 
{
        $username = $_REQUEST['user'];
        $password = $_REQUEST['pass'];
        $sql = mysqli_query($conn,"SELECT * FROM `accountants` where `acc_email` = '".$username."' AND `acc_pass` = '".$password."'");
        $data = mysqli_fetch_array($sql);        
        $_SESSION['role0']=$data['roleId'];
        $_SESSION['username']=$data['acc_name'];
        $sql1 = mysqli_query($conn,"SELECT * FROM `superadmin` where `username` = '".$username."' AND `password` = '".$password."'");
        $data1 = mysqli_fetch_array($sql1);        
        $_SESSION['role1']=$data1['roleId'];
        if ($data>0) 
            {
                header('Location: societyList.php');
            }
       elseif ($data1>0) {
                header('Location: home.php');
       }

       else
            {
                header('Location: index.php');
                echo 'incorrect login';
            }
}

你可以看到列表。我希望如果<div id="sidebar-menu" class="main_menu_side hidden-print main_menu"> <div class="menu_section"> <h3>General</h3> <ul class="nav side-menu"> <li><a><i class="fa fa-home"></i> Home <span class="fa fa-chevron-down"></span></a> <ul class="nav child_menu"> <li><a href="index01.php">Create Society</a></li> </ul> </li> <li><a><i class="fa fa-home"></i> Master <span class="fa fa-chevron-down"></span></a> <ul class="nav child_menu"> <li><a href="index1.php">Units</a></li> <li><a href="index2.php">Members</a></li> <li><a href="index2.php">Parking Lots</a></li> <li><a href="index2.php">Charges</a></li> <li><a href="index2.php">Chart of Account</a></li> <li><a href="index2.php">Interest Penalties</a></li> <li><a href="form_buttons.php">Billing Templates</a></li> <li><a href="form_buttons.php">Tax Structure</a></li> </ul> </li> <li><a><i class="fa fa-edit"></i> Transactions <span class="fa fa-chevron-down"></span></a> <ul class="nav child_menu"> <li><a href="form.php">Bill</a></li> <li><a href="form_advanced.php">Collection</a></li> <li><a href="form_validation.php">Expenses</a></li> <li><a href="form_wizards.php">Journal</a></li> <li><a href="form_upload.php">Bank Reco</a></li> <li><a href="form_buttons.php">Drop Box</a></li> <li><a href="form_upload.php">Online Payment</a></li> </ul> </li> <li><a><i class="fa fa-desktop"></i> Reports <span class="fa fa-chevron-down"></span></a> <ul class="nav child_menu"> <li><a href="general_elements.php">Income & Expenses</a></li> <li><a href="media_gallery.php">Balance Sheet</a></li> <li><a href="typography.php">Cash Flow</a></li> <li><a href="icons.php">Interest Calculation</a></li> </ul> </li> <li><a href="tables.php"><i class="fa fa-table"></i> Notices <span class="fa fa-chevron-down"></span></a> </li> <li><a><i class="fa fa-bar-chart-o"></i> Registers <span class="fa fa-chevron-down"></span></a> <ul class="nav child_menu"> <li><a href="chartjs.php">Form-I</a></li> </ul> </li> <li><a><i class="fa fa-clone"></i> Forum <span class="fa fa-chevron-down"></span></a> <ul class="nav child_menu"> <li><a href="fixed_sidebar.php">Cultural Activity</a></li> </ul> </li> <li><a><i class="fa fa-edit"></i> Domestic Help <span class="fa fa-chevron-down"></span></a> <ul class="nav child_menu"> <li><a href="form.php">Request for Plumber</a></li> <li><a href="form_advanced.php">Request for Maid</a></li> <li><a href="form_validation.php">Request for House Cleaner</a></li> </ul> </li> <li><a><i class="fa fa-edit"></i> Emergency <span class="fa fa-chevron-down"></span></a> <ul class="nav child_menu"> <li><a href="form.php">Ambulance</a></li> <li><a href="form_advanced.php">Fire Brigade</a></li> <li><a href="form_validation.php">Police</a></li> </ul> </li> <li><a><i class="fa fa-edit"></i> Helpdesk <span class="fa fa-chevron-down"></span></a> <ul class="nav child_menu"> <li><a href="form.php">Request NOC for Tenancy</a></li> <li><a href="form_advanced.php">Request NOC for Home Loan</a></li> <li><a href="form_validation.php">Request NOC for Mortgage as collateral</a></li> <li><a href="form_wizards.php">Request for Vehicle Parking</a></li> <li><a href="form_upload.php">Application for Transfer</a></li> <li><a href="form_buttons.php">Request for waiver of interest</a></li> <li><a href="form_buttons.php">Request for waiver of a charge</a></li> <li><a href="form_buttons.php">Suggestion</a></li> <li><a><i class="fa fa-edit"></i><span class="fa fa-chevron-down"></span>Complaint</a> <ul class="nav child_menu"> <li><a href="form_buttons.php">About leakage</a></li> <li><a href="form_buttons.php">About tenants issues</a></li> <li><a href="form_buttons.php">About parking nuisance</a> </ul> </li> </ul> </li> <li><a><i class="fa fa-edit"></i> CFO Desk Assists <span class="fa fa-chevron-down"></span></a> <ul class="nav child_menu"> <li><a href="form.php">Tenant Rating</a></li> <li><a href="form_advanced.php">Owners Rating</a></li> <li><a href="form_validation.php">Your Reviews</a></li> </ul> </li> <li><a><i class="fa fa-edit"></i> Masters <span class="fa fa-chevron-down"></span></a> <ul class="nav child_menu"> <li><a href="form.php">Auto Bank reconcilliation</a></li> <li><a href="form_advanced.php">AMC Masters</a></li> <li><a href="form_validation.php">Auto Adjust pending reference</a></li> <li><a href="form_wizards.php">Default GL for defined transactions</a></li> </ul> </li> </ul> </div> </div> 在会话中,那么前4个列表将仅对他可见。 如果会话中有$_SESSION['role0']=$data['roleId'];,则会向他显示所有列表的其余部分。 如何做到这一点请帮助我。我使用的条件就像 $_SESSION['role1']=$data['roleId'];  如果我这样使用,如果条件没有显示。

1 个答案:

答案 0 :(得分:0)

会话数据记录存储在$ _REQUEST。

$_SESSION['role0']=$data1['roleId'];
$_SESSION['role1']=$data1['roleId'];

'role0'和'role1'都具有相同的值。它可以简化为:

$_SESSION['role']=$data1['roleId'];

然后使用:

if( $_SESSION['role'] === 1) {
    echo 'admin role 1';
    echo 'Show first half of menu';
} elseif ($_SESSION['role'] === 2) {
    echo 'Show second half of menu';
} else {
    echo 'Other or missing admin value. show no menu';
}

SQL注入可能是当前编写的方式。准备好的陈述将是下一步添加的好事。