PHP 限制访问,除非登录

标签 php mysql .htaccess

我正在创建自己的管理面板,我希望成为唯一可以登录的人。我想使用登录表单来执行此操作,但不想使用 .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>
    &copy; <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 ;

关于PHP 限制访问,除非登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26570100/

相关文章:

php - MySQL join 将多行匹配为单列数据

php - exec() 错误响应

mysql - 无法加载文件或程序集 'MySql.Data' 或其依赖项之一

apache - %25 附加在 htaccess 重定向的 Url 中

php - 在单独的 div 中显示多个 MySQL 记录

javascript - 请求的资源上不存在 'Access-Control-Allow-Origin' header 。我不知道该怎么办

mysql - 无法连接为使用 Ansible 创建的 MySQL 用户

php - 您的 SQL 语法有误

apache - 如何在 htaccess 中将除一个页面之外的所有页面定向到 HTTPS?

regex - htaccess 如何将子目录重定向到外部 URL