How to do a redirect to the admin panel?

Doing a redirect to the admin panel. Challenge : if people try to keep in the address bar the path to the admin panel, it will transfer on an authorization form. Difficulties

Created the file functions.php
<?php
$mysqli = false;

function connectDB() {
 global $mysqli;
 $mysqli = new mysqli("localhost", "root", "", "Hunter");
}

function checkUser($login) {
 global $mysqli;
connectDB();
 $result_set = $mysqli--->query ("SELECT * FROM `admin` WHERE 'login'='$login' AND 'password'='$password'");
 $row = $result_set->fetch_assoc();
closeDB();
 if ($result_set->fetch_assoc()) return true;
 else return false;

}
function isAdmin($login) {
 global $mysqli;
connectDB();
 $result_set = $mysqli->query ("SELECT * FROM `admin` WHERE 'login'='$login'");
 $row = $result_set->fetch_assoc();
closeDB();
 return $row["ident"];

}
function closeDB() {
 global $mysqli;
$mysqli->close();
}
?>


The admin table has 4 fields : id, login, password, ident. indent - just nake ID(unit)

At the top of the authorization form write:
<?php
session_start();
require_once "lib/functions.php";
if (checkUser($_SESSION["login"], $_SESSION["password"])){
 header("Location: index.php");
exit;
}
?>


Initialize a session > connect file function.php > the condition (if the administrator is already logged in, throw on the admin panel). Well, from below the login form

For the admin panel create a file start.php write :
<?php
session_start();
require_once "/lib/functions.php";
if (!((checkUser($_SESSION["login"], $_SESSION["password"])) && 
(isAdmin($_SESSION["login"])))) {
 header("Location: login.php");
exit;
}
?>

Connect file functions.php > the condition for the negation of the > redirect to the login form

Well, on the admin panel connect file start.php.

A redirect is when I try to path to admin panel > transferred to the authorization form. But when I enter data ( login and password), the form refreshes, or redirect occurs. Help to modify the code to point out errors. I need help!

Authorization code :
<?php
 require_once "/lib/functions.php";
 $login = htmlspecialchars ($_POST["login"]);
 $password = htmlspecialchars ($_POST["password"]);
 $password = md5($password );
 if (checkUser($login, $password)) {
 $_SESSION["login"] = $login;
 $_SESSION["password"] = $password;
}
 else $_SESSION["error_auth"] = 1;
 header("Location: index.php");
exit
?>
June 26th 19 at 14:26
0 answer

Find more questions by tags PHP