Skip to content

Instantly share code, notes, and snippets.

@greyaperez
Created March 21, 2014 14:16
Show Gist options
  • Save greyaperez/9687176 to your computer and use it in GitHub Desktop.
Save greyaperez/9687176 to your computer and use it in GitHub Desktop.
Very quick and dirty login, just add this entire script above the stuff in your index.php file.
<?php
// SET YOUR USER/PASS STUFF HERE...
$auth = array(
'user1' => 'pass123',
'user2' => 'pass123',
'user3' => 'pass123',
'user4' => 'pass123',
'user5' => 'pass123',
);
/////////////////////////////////////////////////
// DON'T WORRY ABOUT THIS CRAP
/////////////////////////////////////////////////
session_cache_limiter('private');
$cache_limiter = session_cache_limiter();
session_cache_expire(60 * 24);
$cache_expire = session_cache_expire();
session_start();
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
function showLogin(){
echo 'login';
$form = '<form method="post" action="" name="login">';
$form .= 'User: <input name="user" type="text" />';
$form .= '<br>';
$form .= 'Pass: <input name="pass" type="text" />';
$form .= '<input name="submit" type="submit" value="Login" />';
$form .= '</form>';
echo $form;
die();
}
$showLogin = true;
$user = (isset($_POST['user'])) ? @$_POST['user'] : '';
$pass = (isset($_POST['pass'])) ? @$_POST['pass'] : '';
if( isset($_SESSION['authenticated']) && $_SESSION['authenticated'] == true ){
$showLogin = false;
} else if (isset($_POST['user']) && isset($_POST['pass'])){
// Check Login
if(isset($auth[$user]) && $auth[$user] === $pass){
$_SESSION['authenticated'] = true;
$showLogin = false;
}
}
if($showLogin == true){ showLogin(); }
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment