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();       
}

works for me
The var_dumps might mess up your <meta refresh>

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

$allowed_users = array('User1');

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.