Skip to content

Instantly share code, notes, and snippets.

@pixelbart
Created September 24, 2016 19:22
Show Gist options
  • Save pixelbart/bb662ab7f78cfad0759b771e5f1ef700 to your computer and use it in GitHub Desktop.
Save pixelbart/bb662ab7f78cfad0759b771e5f1ef700 to your computer and use it in GitHub Desktop.
Simple JSON login function
<?php
$files = array();
$login_nick = null;
$login_pass = null;
//* loop all user files in users/ with file ending .json
foreach(glob('users/*.json') as $file) :
//* put json file contents into the users array
$users[] = json_decode(file_get_contents($file));
endforeach;
//* Get nicks from user files
foreach($users as $user) :
//* Put nicks in array
$nicks[] = $user->user_nick;
endforeach;
//* Check if user exists
if( in_array( $nick_login, $nicks ) ) :
foreach($users as $user) :
//* Check if user exists if true, go to password check
if($user->user_nick == $nick_login) :
//* Check if password is correct
if($user->user_password == $password_login) :
//* All ready
echo 'ok';
else :
//* No pass found
echo 'no pass';
endif;
else :
//* No user found
echo 'no user';
endif;
endforeach;
else :
//* No user found
echo 'no user';
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment