Skip to content
Advertisement

PHP Multiple Username & Passwords

So, this is probably the simplest question I could ever possibly ask.. Though it is driving me insane. In my login system, I have it set up to read the username and password from a standalone file “users.php” inside it contains

<?php
$user = 'username';
$password = 'password';
?>

I can not, for the life of me figure out how to make it read multiple usernames and passwords. I have tried multiple different variations… If I just add more $user and $password lines, the login will ONLY accept the last set.

I have tried:

<?php
$user = 'username', 'user';
$password = 'password', 'password';
?>

<?php
$user = 'username, user';
$password = 'password, password';
?>

and both with ” instead of ‘

if anyone has a suggestion, please let me know :3 Thank you!~

Advertisement

Answer

Not quite sure what you are asking, but if your trying to store multiple users, with different names/pass..

<?php
    $usernames = ['john', 'smith', 'simon', 'bob'];
    $passwords = ['2rre', '423dasd', 'D#322', 'd3r23'];

  for($i=0; $i < count($usernames); $i++){
    echo 'username '.$usernames[$i].' has password: '.$passwords[$i].'<br/>';
   }

Will echo out:

username john has password: 2rre
username smith has password: 423dasd
username simon has password: D#322
username bob has password: d3r23
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement