rvimalram Posted February 26, 2015 Share Posted February 26, 2015 Need Help!!! I am trying to build an application in php without database connectivity. I have a index page where i have 6 users. 1 among the 6 users will act as admin. I am using array to get the username & password When the users logs in, some of the options should be disabled or non-editable. Assume "raj" plays the admin role Code what i have: <?php session_start(); /* Starts the session */ /* Check Login form submitted */ if(isset($_POST['Submit'])){ /* Define username and associated password array */ $logins = array('raj' => 'raj123@123','ram' => 'ram@123','dev' => 'dev@123','dave' => 'dave@123','Sugi' => 'sugi@123','raki' => 'raki@123','sam' => 'sam@123'); /* Check and assign submitted Username and Password to new variable */ $Username = isset($_POST['Username']) ? $_POST['Username'] : ''; $Password = isset($_POST['Password']) ? $_POST['Password'] : ''; /* Check Username and Password existence in defined array */ if (isset($logins[$Username]) && $logins[$Username] == $Password){ /* Success: Set session variables and redirect to Protected page */ $_SESSION['UserData']['Username']=$logins[$Username]; header("location:signin.php"); exit; } else { /*Unsuccessful attempt: Set error message */ $msg="<span style='color:red'>Invalid Login Details</span>"; } } ?> Any help on this will be much appreciated!!!! Thanks Quote Link to comment https://forums.phpfreaks.com/topic/294915-php-application-without-database/ Share on other sites More sharing options...
Ch0cu3r Posted February 26, 2015 Share Posted February 26, 2015 What are you asking? You want to make the user logged in as Jaj to have the role as admin? You could change your login array to something like this $logins = array('raj' => array('raj123@123', 'admin' => true), 'ram' => array('ram@123'), 'dev' => array('dev@123'), ...etc ); Then for logging user in if (isset($logins[$Username]) && $logins[$Username][0] == $Password) { /* Success: Set session variables and redirect to Protected page */ $_SESSION['UserData']['Username']=$logins[$Username]; // This is set to true if the admin key exists and is set to true for user logging in $_SESSION['UserData']['Admin'] = (isset($logins[$Username]['admin']) && $logins[$Username]['admin'] == true); header("location:signin.php"); exit; } else { /*Unsuccessful attempt: Set error message */ $msg="<span style='color:red'>Invalid Login Details</span>"; } Quote Link to comment https://forums.phpfreaks.com/topic/294915-php-application-without-database/#findComment-1506803 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.