我一直致力于保护服务器上的某些页面。我能够创建一个登录屏幕和所有,它完美地工作。在那之后,我决定通过添加一些CSS(背景,水平中心对齐等)来实现它。在那之后,出于某种原因,即使在我输入我的登录信息之后,之前没有任何处理,我可以在登录后看到页面的其余部分。
我实现登录的方式是,我创建了一个名为login.php
的页面,我还有index.php
,我试图访问的页面。在index.php
中,我使用require
始终首先访问login.php
。我也theme.css
让事情变得更好。
我不明白的是,它之前是如何运作的,但现在它突然停止了工作。在登录页面工作后,我甚至没有触摸除CSS文件之外的任何内容。
以下是我的代码:
的index.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>
的login.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;
?>
theme.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;
}
对于您可以提供给我的这个问题的任何见解,我将非常感激。请让我知道,谢谢!
答案 0 :(得分:1)
在login.php中,您的</form>
标记位置错误。
login.php表单应编码如下: -
<br />
<form method="post"> <!-- moved! -->
<table class="center">
<tr>
<td>Username:</td>
<td><input type="text" name="username"></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="password"></td>
</tr>
</table>
<input type="submit" name="submit" value="Login">
</form> <!-- moved! -->
答案 1 :(得分:0)
您的代码和页面中存在许多错误。 我解决了所有问题,并通过集成代码来制作您想要的页面。
根据下面给出的代码更改页面(不要更改你的CSS及其名称。你的“CSS”工作正常。):
<强>的index.php 强>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<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 action="aunthiticate.php" 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>
<tr><td colspan="2"> <input type="submit" name="submit" value="Login"></td></tr>
</form>
</table>
</div>
</div>
</div>
</body>
<强>的login.php 强>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>Protected Page</title>
<link rel="stylesheet" href="css/theme.css" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<强> aunthiticate.php 强>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<?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 (($_POST['password'] == $password1) && ($_POST['username'] == $uname1))
{
$_SESSION['logged'] = true;
$user = $_POST['username'];
$pwd = $_POST['password'];
header('location:login.php');
}
else
{
die ('Incorrect password');
session_destroy();
}
}
?>
</body>
</html>
<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>