[英]PHP Restrict access unless logged in
我正在創建自己的管理面板,並且希望成為唯一可以登錄的人。我想使用一種登錄表單來執行此操作,但我不想使用.htaccess或.htpassword進行登錄。
這是我的login.php文件:
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
<!--[if IE 7]> <html class="lt-ie9 lt-ie8" lang="en"> <![endif]-->
<!--[if IE 8]> <html class="lt-ie9" lang="en"> <![endif]-->
<!--[if gt IE 8]><!-->
<html lang="en"> <!--<![endif]-->
<link rel="stylesheet" href="css/style.css">
<!--[if lt IE 9]><script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
<head>
<meta charset="utf-8">
<title>Admin Login</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
</head>
<body>
<form method="post" action="index.php" class="login">
<p>
<label for="login">Email:</label>
<input type="text" name="login" id="login" value="name@example.com">
</p>
<p>
<label for="password">Password:</label>
<input type="password" name="password" id="password" value="4815162342">
</p>
<p class="login-submit">
<button type="submit" class="login-button">Login</button>
</p>
<p class="forgot-password"><a href="index.html">Forgot your password?</a></p>
</form>
</body>
<div id="footer">
<footer>
© <a href="http://deathsrepo.pw">Technologx 2013-2014</a>
</footer>
</div>
</html>
這是我的index.php:
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Technologx Admin Panel</title>
<style>
body {
background: #000;
text-align: center;
}
#container {
display: inline-block;
padding: 5px;
margin: 60px;
background: #045FB4;
position: relative;
-webkit-border-radius: 100px;
-moz-border-radius: 100px;
border-radius: 100px;
-webkit-box-shadow: inset 0px 1px 2px 0px #2EFEF7, 0px 1px 1px 0px #2EFEF7;
-moz-box-shadow: inset 0px 1px 2px 0px #2EFEF7, 0px 1px 1px 0px #00FF80;
box-shadow: inset 0px 1px 2px 0px #2EFEF7, 0px 1px 1px 0px #2EFEF7;
-webkit-transition: all .2s ease;
-moz-transition: all .2s ease;
-ms-transition: all .2s ease;
-o-transition: all .2s ease;
transition: all .2s ease;
}
#container ul {
padding: 0;
height: 40px;
margin: 0;
list-style: none;
overflow: hidden;
-webkit-box-shadow: inset 0px 1px 1px 0px #FA58D0, 0px 1px 2px 0px #FA58D0;
-moz-box-shadow: inset 0px 1px 1px 0px #FA58D0, 0px 1px 2px 0px #FA58D0;
box-shadow: inset 0px 1px 1px 0px #FA58D0, 0px 1px 2px 0px #FA58D0;
background: #8A084B;
background-image: -moz-linear-gradient(top, rgba(0,0,0,0) 0%, rgba(0,0,0,0.3) 100%);
background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(0,0,0,0)), color-stop(100%,rgba(0,0,0,0.3)));
background-image: -webkit-linear-gradient(top, rgba(0,0,0,0) 0%,rgba(0,0,0,0.3) 100%);
background-image: -o-linear-gradient(top, rgba(0,0,0,0) 0%,rgba(0,0,0,0.3) 100%);
background-image: -ms-linear-gradient(top, rgba(0,0,0,0) 0%,rgba(0,0,0,0.3) 100%);
background-image: linear-gradient(top, rgba(0,0,0,0) 0%,rgba(0,0,0,0.3) 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#FA8258', endColorstr='#DF7401',GradientType=0 );
-webkit-border-radius: 100px;
-moz-border-radius: 100px;
border-radius: 100px;
}
#container ul li {
background: rgba(255,255,255,0.0);
float: left;
text-align: center;
border-right: 1px solid #666;
border-left: 1px solid #444;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
-webkit-transition: all .2s ease;
-moz-transition: all .2s ease;
-ms-transition: all .2s ease;
-o-transition: all .2s ease;
transition: all .2s ease;
}
#container ul li:hover {
background: rgba(255,255,255,0.08);
}
#container ul li:active {
background: rgba(0,0,0,0.08);
}
#container ul li:first-child {
border-left: none;
-webkit-border-radius: 100px 0 0 100px;
-moz-border-radius: 100px 0 0 100px;
border-radius: 100px 0 0 100px;
}
#container ul li:last-child {
border-right: none;
-webkit-border-radius: 0 100px 100px 0;
-moz-border-radius: 0 100px 100px 0;
border-radius: 0 100px 100px 0;
}
#container ul li a{
text-decoration: none;
font: 11px/41px Arial, sans-serif;
color: #ddd;
text-transform: uppercase;
text-shadow: 0px 1px rgba(0,0,0,0.5);
padding: 35px;
}
</style>
<?php
session_start();
require_once('login.php');
?>
</head>
<div id="container">
<ul>
<li><a href="http://upload.deathsrepo.pw/views.php">Visits</a></li>
<li><a href ="login.php">Log out</a></li>
</ul>
</div>
<body>
</body>
</html>
我在整個Google上都看過教程,但是找不到任何東西,如果我這樣做是行不通的。 我希望它使用mySQL來存儲我的登錄信息,但是我想對密碼進行加密。
CREATE TABLE `members` (
`id` int(4) NOT NULL auto_increment,
`username` varchar(65) NOT NULL default '',
`password` varchar(65) NOT NULL default '',
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=2 ;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.