Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/294915-php-application-without-database/
Share on other sites

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>";
}
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.