Help for a PHP Beginner
Okay, I'm hoping somebody can help me with this. I'm a total beginner when it comes to writing PHP from scratch, and I'm trying to throw a bunch of things together an make them work.
Here's what's up: I have a simple login form—very very basic with minimal security (it doesn't really need to be secure). The usernames and passwords are just a few different logins predefined by the site owner, so they're just retrieved and checked through an array, like this:
Once the form is posted, the PHP page it posts to verifies that the password and username match one of the arrays, as shown below. That's all working swell and great.
This is retrieving the username and password from the form and turning it into their respective variables:
Then this loops through the arrays to find the user names and passwords and make sure they match
There's more regarding logouts, and bad seesions, etc. but that's the only important part in regard to making the next part I need work.
Okay, back up to my array you'll see a third value (or second, [2], I guess, in PHP-counting-land). That one defines the user type, which I want to use to control what content the user sees.
I've been trying to figure out how to write the PHP so that it finds the array that contains the matching $user variable and then picks up the third (or [2]) value from that array. So then I can make an if/else statement depending on whether the value in the array is "type_poweruser" or "type_normaluser". Does that make sense?
For example, if the posted $user variable was "username2", I want it to find the array with "username2" and see that that array has the value "type_normaluser", and then be able to say, if type is "type_normmaluser", then display 'f00".
I'm fine with figuring out how to do the "if type is "type_normmaluser", then display 'f00'" part— I just don't know how to get it to know which "type" it is.
I just don't have my syntax down nearly well enough to get it right. I've tried about a hundred variations of using in_array (e.g. "if (in_array($username, $users)..." but I just can't get it.
...help?
Here's what's up: I have a simple login form—very very basic with minimal security (it doesn't really need to be secure). The usernames and passwords are just a few different logins predefined by the site owner, so they're just retrieved and checked through an array, like this:
$users = array(
array("username1","password1", "type_poweruser"),
array("username2","password2", "type_normaluser"),
array("username3","password3", "type_normaluser"),
(...et cetera)
);
Once the form is posted, the PHP page it posts to verifies that the password and username match one of the arrays, as shown below. That's all working swell and great.
This is retrieving the username and password from the form and turning it into their respective variables:
$username = $_POST['username'];
$password = $_POST['password'];
Then this loops through the arrays to find the user names and passwords and make sure they match
foreach($users as $values){
if($username== $values[0] && $password == $values[1]){
//If user and pass match any of the defined users
$_SESSION['manual_loggedin'] = true;
};
};
There's more regarding logouts, and bad seesions, etc. but that's the only important part in regard to making the next part I need work.
Okay, back up to my array you'll see a third value (or second, [2], I guess, in PHP-counting-land). That one defines the user type, which I want to use to control what content the user sees.
I've been trying to figure out how to write the PHP so that it finds the array that contains the matching $user variable and then picks up the third (or [2]) value from that array. So then I can make an if/else statement depending on whether the value in the array is "type_poweruser" or "type_normaluser". Does that make sense?
For example, if the posted $user variable was "username2", I want it to find the array with "username2" and see that that array has the value "type_normaluser", and then be able to say, if type is "type_normmaluser", then display 'f00".
I'm fine with figuring out how to do the "if type is "type_normmaluser", then display 'f00'" part— I just don't know how to get it to know which "type" it is.
I just don't have my syntax down nearly well enough to get it right. I've tried about a hundred variations of using in_array (e.g. "if (in_array($username, $users)..." but I just can't get it.
...help?
