0

want to restrict users to access particular webpages in my applicatipn. In my application I have 4 webpages like Mumbai, Delhi, Bangalore, Kolkata and I have havie 4 users say User1, User2, User3 and User4. All users are Admin.

My requirement is that all 4 user can't access Mumbai page, User1 can access only Delhi page, User2 and User3 can access only Bangalore page and User4 can access only Kolkata page.

I Used following Code but it din't work

<?php
session_start();
$_SESSION['username'] = 'User1';
$login_session = array(
    'id'            =>  session_id(),
    'login_user'    =>  $_SESSION['username']
);
var_dump($login_session['login_user']); // User1
$allowed_users = array('User2','User3','User4');
var_dump(in_array($login_session['login_user'], $allowed_users)); // bool False
if (!in_array($login_session['login_user'], $allowed_users)) { //Check if the logged user is not in this array (False)
   echo "You dont have permission to access this page";
   echo '<meta http-equiv="refresh" content="5; url=include1.php">'; // Printed and redirected
   exit();       
}
2
Contributors
3
Replies
21
Views
3 Years
Discussion Span
Last Post by pzuurveen
0

Hello,
Its not working for me.
I want to give Acces to User1 & not for others But it not working

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.