我一直在努力保护我服务器上的一些页面。我能够创建一个登录屏幕和所有内容,并且运行良好。之后,我决定通过添加一些 CSS(背景、水平居中对齐等)来美化它。在那之后,出于某种原因,即使我输入了登录信息,之前也没有任何处理,登录后我将能够看到页面的其余部分。
我实现登录的方式是,我创建了一个名为 的页面login.php
,并且我也有index.php
一个我试图访问的页面。在index.php
,我require
以前总是login.php
先访问。我还必须theme.css
让事情看起来更好。
我不明白的是,它以前是怎么工作的,但现在突然停止工作了。登录页面正常工作后,除了 CSS 文件之外,我什至没有触摸任何东西。
这是我的代码:
索引.php
<?php
require('login.php');
?>
<?php
require('session.php');
?>
<html>
<head>
<title>Protected Page</title>
<link rel="stylesheet" href="css/theme.css" type="text/css">
</head>
<body>
<form enctype="multipart/form-data" action="add.php" method="POST">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name = "email"><br>
Phone: <input type="text" name = "phone"><br>
Photo: <input type="file" name="photo"><br>
<input type="submit" value="Add">
</form>
<table>
<tr>
<td><form method="post"><input type="submit" name="submit" value="Check Status"></form></td>
<td><form action="logout.php" method="post"><input type="submit" name="submit" value="Logout"></form></td>
</tr>
</table>
</body>
</html>
登录.php
<?php
## put sha1() encrypted password here - example is 'hello'
$password1 = '43b1c8633e86765546bb1f44c4d654ed223fa064';
## username dictionary
$uname1 = 'ismail';
session_start();
if (!isset($_SESSION['logged']))
{
$_SESSION['logged'] = false;
}
if (isset($_POST['password']))
{
if ((sha1($_POST['password']) == $password1) && ($_POST['username'] == $uname1))
{
$_SESSION['logged'] = true;
$user = $_POST['username'];
$pwd = $_POST['password'];
}
else
{
die ('Incorrect password');
session_destroy();
}
}
if (!$_SESSION['logged']):
?>
<html>
<head>
<title>Login</title>
<link rel="stylesheet" href="css/theme.css" type="text/css">
</head>
<body>
<div class="container">
<div class="vcenter">
<div id="box-login">
<img src="images/logo1.jpg" alt="PT BPI Logo" height="120px" class="center">
<br />
<table class="center">
<form method="post">
<tr>
<td>Username:</td>
<td><input type="text" name="username"></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="password"></td>
</tr>
</form>
</table>
<input type="submit" name="submit" value="Login">
</div>
</div>
</div>
</body>
</html>
<?php
exit();
endif;
?>
主题.css
/*
AUTHOR: Ismail Fadillah Adiputra
VERSION: 1.0 | 20131030
*/
/* general */
body {
margin:0;
padding:0;
background: -webkit-radial-gradient(#EDEDED, #9AC1DB); /* Safari */
background: -o-radial-gradient(#EDEDED, #9AC1DB); /* For Opera 11.1 to 12.0 */
background: -moz-radial-gradient(#EDEDED, #9AC1DB); /* For Firefox 3.6 to 15 */
background: radial-gradient(#EDEDED, #9AC1DB); /* Standard syntax */
}
h1, h2, h3, h4, h5, h6 { font-family:'Tahoma', Helvetica, Arial, sans-serif; color:#656464; text-transform:uppercase; font-weight:normal; text-align:center; }
h1 { font-size:3em; margin:0; }
h2 { font-size:3.4em; }
p { font-family:'Tahoma', Helvetica, Arial, sans-serif; color:#656464; font-size:13px; }
a { border-bottom:1px dotted; }
a:hover { border-bottom:1px solid; }
input { font-family:'Tahoma', Helvetica, Arial, sans-serif; color:#656464; font-size:13px; }
td { font-family:'Tahoma', Helvetica, Arial, sans-serif; color:#656464; font-size:13px; }
/* Appearance of the box in the login page */
#box-login {
background:white;
padding:10px 0px 10px 0px; /* padding top, right, bottom, left (in order) */
border-radius:5px; /* rounded corner */
box-shadow: 5px 5px 10px #888888; /* shadow */
margin:185px auto; /* horizontal align center */
width:275px;
}
.container {
position:relative;
width:100%;
}
.right {
position:absolute;
right:0px;
width:300px;
background-color:#b0e0e6;
}
/*
.center {
margin:auto;
width:50%;
}
*/
.center {
/* center align the right way */
float:none;
display:block;
margin:auto;
}
/* Changing the appearance of the input button */
input[type="submit"] {
float:none;
display:block;
margin:10px auto;
background:#EDEDED;
text-decoration:none;
font-family:'Tahoma';
font-size:11px;
color:#656464;
}
input[type="submit"]:hover {
float:none;
display:block;
margin:10px auto;
background:#656464;
text-decoration:none;
font-family:'Tahoma';
font-size:11px;
color:#EDEDED;
}
您可以向我提供有关此问题的任何见解,我将不胜感激。请告诉我,谢谢!