Admin pages

from https://github.com/mariofont/PHP-Login
This commit is contained in:
2022-04-12 18:03:06 +02:00
parent 053598bf47
commit 2c36f7af82
6 changed files with 160 additions and 1 deletions

5
admin/config.php Normal file
View File

@@ -0,0 +1,5 @@
<?php
/* Define username and password */
$Username = 'Bruno';
$Password = '$2y$10$Redt0pUHUm8.UBFbkfRdcuAY49HpsUzxqtS3b38i7emvdrzvHaC9K';

69
admin/index.php Normal file
View File

@@ -0,0 +1,69 @@
<?php
session_start(); /* Starts the session */
if($_SESSION['Active'] == false){ /* Redirects user to Login.php if not logged in */
header("location:login.php");
exit;
}
?>
<!-- Show password protected content down here -->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="css/stylesheet.css">
<title>Logged in</title>
</head>
<body>
<div class="container">
<div class="header clearfix">
<nav>
<ul class="nav nav-pills pull-right">
<li role="presentation" class="active"><a href="../index.php">Home</a></li>
<li role="presentation"><a href="../about.php">About</a></li>
<li role="presentation"><a href="../photo-du-mois.php">Photo du mois</a></li>
<li role="presentation"><a href="../maps.php">Maps</a></li>
</ul>
</nav>
<h3 class="text-muted">Sur-le-sentier by @clicclac</h3>
</div>
<div class="jumbotron">
<h1>Status: logged in</h1>
<p class="lead">A password protected area for admin pages!</p>
<p><a class="btn btn-lg btn-success" href="logout.php" role="button">Log out</a></p>
</div>
<div class="row marketing">
<div class="col-lg-6">
<h4>Inserting</h4>
<p><a href="../insert_bdd.php">Insert_bdd</a></p>
<h4>Viewing</h4>
<p><a href="../insert_bdd.php">View_bdd</a></p>
</div>
<div class="col-lg-6">
<h4>Cleaning</h4>
<p><a href="../insert_bdd.php">Clean_bdd</a></p>
</div>
</div>
<footer class="footer">
<p>&copy; 2013-<?php echo date('Y'); ?> sur-le-sentier.fr</p>
</footer>
</div>
<script src="../../assets/js/ie10-viewport-bug-workaround.js"></script>
</body>
</html>

74
admin/login.php Normal file
View File

@@ -0,0 +1,74 @@
<?php
require_once ('config.php'); // For storing username and password.
session_start();
?>
<!-- HTML code for Bootstrap framework and form design -->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="css/signin.css">
<title>Sign in</title>
</head>
<body>
<div class="container">
<form action="" method="post" name="Login_Form" class="form-signin">
<h2 class="form-signin-heading">Please sign in</h2>
<label for="inputUsername" class="sr-only">Username</label>
<input name="Username" type="username" id="inputUsername" class="form-control" placeholder="Username" required autofocus>
<label for="inputPassword" class="sr-only">Password</label>
<input name="Password" type="password" id="inputPassword" class="form-control" placeholder="Password" required>
<div class="checkbox">
<label>
<input type="checkbox" value="remember-me"> Remember me
</label>
</div>
<button name="Submit" value="Login" class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
<?php
/* Check if login form has been submitted */
if(isset($_POST['Submit'])){
// Rudimentary hash check
$result = password_verify($_POST['Password'], $Password);
/* Check if form's username and password matches */
if( ($_POST['Username'] == $Username) && ($result === true) ) {
/* Success: Set session variables and redirect to protected page */
$_SESSION['Username'] = $Username;
$_SESSION['Active'] = true;
header("location:index.php");
exit;
} else {
?>
<!-- Show an error alert -->
&nbsp;
<div class="alert alert-danger alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<strong>Warning!</strong> Incorrect information.
</div>
<?php
}
}
?>
</form>
</div>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) >
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script-->
<!-- Include all compiled plugins (below), or include individual files as needed >
<script src="js/bootstrap.min.js"></script-->
</body>
</html>

6
admin/logout.php Normal file
View File

@@ -0,0 +1,6 @@
<?php
session_start(); /* Starts the session */
session_destroy(); /* Destroy started session */
header("location:login.php"); /* Redirect to login page */
exit;

View File

@@ -150,7 +150,7 @@ $("#exemple, body").vegas({
</div>
<div class="vegas-info">
<a href="close.php">close</a>a><?php echo gettext('Powered by'); ?> <a href="https://wordpress.org">WordPress</a> - <a href="https://www.zenphoto.org">Zenphoto</a> - <a href="https://vegas.jaysalvat.com">Vegas Background Slideshow 2</a>. <a href="">License des photos</a>. (c) 2013-<?php echo date('Y'); ?> sur-le-sentier.fr
<a href="close.php">close</a>a><?php echo gettext('Powered by'); ?> <a href="https://wordpress.org">WordPress</a> - <a href="https://www.zenphoto.org">Zenphoto</a> - <a href="https://vegas.jaysalvat.com">Vegas Background Slideshow 2</a>. <a href="">License des photos</a>. &copy; 2013-<?php echo date('Y'); ?> sur-le-sentier.fr
</div>
</body>

View File

@@ -14,6 +14,11 @@
<?php include 'functions.php';
session_start();
if($_SESSION['Active'] == false){ /* Redirects user to login.php if not logged in */
header("location:admin/login.php");
exit;
}
$domain = 'sentier';
localize($domain);
?>