<head>
<script type="text/javascript" src="js/jquery.js"></script>
</head>
<?php
$err = '';
include("dbconnect.php");
require_once 'auth.php';
// If post, check user
if (!empty($_POST['userlogin']) && !empty($_POST['pass'])) {
// Verify user and password
if (isValidUser($_POST['userlogin'], $_POST['pass'], $mysqli)) {
// Log in
$_SESSION['userlogin'] = $_POST['userlogin'];
header('Location: index.php');
exit();
}
else
{
$_SESSION['userlogin'] = FALSE;
}
}
// The user login page
include 'templates/header.php';
?>
<!--login modal-->
<div id="loginModal" class="modal show bs-example-modal-sm" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<form class="form" method="POST" action="login.php">
<div class="modal-header">
<h3 class="text-center">User authentication</h3>
</div>
<div class="modal-body">
<div class="form-group">
<input type="text" class="form-control input-sm" placeholder="login" name="userlogin">
</div>
<div class="form-group">
<input type="password" class="form-control input-sm" placeholder="password" name="pass">
</div>
<p class='mesage_error'><?php echo $err;?></p>
</div>
<div class="modal-footer">
<button class="btn btn-default">Login</button>
</div>
</form>
</div>
</div>
</div>
<?php
include 'templates/footer.php';
<?php
session_start();
include("dbconnect.php");
function authHTML()
{
// if not auhtenticaded session go to login.php
if (empty($_SESSION['userlogin'])) {
header('Location: login.php');
exit();
}
}
function authAPI()
{
$user = isset($_SERVER['PHP_AUTH_USER']) ? $_SERVER['PHP_AUTH_USER'] : '';
$pass = isset($_SERVER['PHP_AUTH_PW']) ? $_SERVER['PHP_AUTH_PW'] : '';
if (!isValidUser($user, $pass)) {
$_SESSION['userlogin'] = FALSE;
header('WWW-Authenticate: Basic realm="My Realm"');
header('HTTP/1.0 401 Unauthorized');
die("Not authorized");
}
$_SESSION['userlogin'] = $user;
}
function isValidUser($user, $pass, $mysqli)
{
$testrole = $mysqli->query("SELECT * FROM `users` WHERE username = '".$user."' AND password = '".$pass."'");
if($testrole->num_rows == 1){
return TRUE;
}else{
return FALSE;
}
}
?>
if (!empty($_POST['userlogin']) && !empty($_POST['pass'])) {
// Verify user and password
if (isValidUser($_POST['userlogin'], $_POST['pass'], $mysqli)) {
// Log in
$_SESSION['userlogin'] = $_POST['userlogin'];
header('Location: index.php');
exit();
}
else
{
// если не соответствует то
$_SESSION['message'] = "Логин или пароль неправильно.";
$_SESSION['userlogin'] = FALSE;
}
}