The following files exists in this folder. Click to view.
login.php57 lines ASCII Unix (LF) 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
<?php
$file_in = "users.json";
$json = json_decode(file_get_contents($file_in), true);
foreach ($json["users"] as $u){
$users[] = $u["usn"];
$pass[] = $u["pwd"];
$status[] = $u["status"];
}
session_start();
$_SESSION["username"]=$_POST["username"];
$_SESSION["password"]=$_POST["password"];
if(isset($_POST["remember"]) and !isset($_COOKIE["username"]) and isset($_POST["username"]) and isset($_POST["password"])){
setcookie("username", $_POST["username"]);
setcookie("password", $_POST["password"]);
}
if(isset($_COOKIE["username"])){
$_SESSION["username"]=$_COOKIE["username"];
$_SESSION["password"]=$_COOKIE["password"];
}
if(!isset($_POST["remember"]) and isset($_POST["username"]) and isset($_POST["password"])){
$_SESSION["username"]=$_POST["username"];
$_SESSION["password"]=$_POST["password"];
}
$uIndex = array_search($_SESSION["username"], $users);
if (in_array($_SESSION["username"], $users) and in_array($_SESSION["password"], $pass) and $pass[$uIndex]==$_SESSION["password"]){
if ($status[$uIndex] == "admin"){
$_SESSION["user"]="Intentionally removed by CSource";
header("location: admin.php");
exit();
}
if ($status[$uIndex] == "user"){
$_SESSION["user"]="Intentionally removed by CSource";
header("location: user.php");
exit();
}
}
else{
setcookie('username', '', time() - 070414);
setcookie('password', '', time() - 070414);
header("location: index.php?mess=ERROR");
exit();
}
?>