这是我的login.php代码:(这是显示表单的页面,要求用户输入6位代码。一旦输入正确的代码并按提交,用户将转到admin.php if代码是正确的
<?php
session_start();
include('connection.php');
?>
<!doctype html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link href="css/reset.css" rel="stylesheet" type="text/css" />
<div id="container">
<div id="authorise">
<form action="admin.php" method="POST" name="authorisation"><br>
<!--Product Comment Box--><br>
<p>Please enter your 4<br> digit authorisation code:<br> <br><input type="text" name="code"/></p><br>
<input type="submit" value="Log In"/>
</form>
<?php
if (isset($_POST['code']) && $_POST['code'] == '210392') {
header("Location: https://www.google.co.uk");
exit;
}
?>
</div>
</div>
这是我的admin.php文件(为复制整件事而道歉)
<!doctype html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link href="css/reset.css" rel="stylesheet" type="text/css" />
<style type="text/css">
table {
font-family: verdana,arial,sans-serif;
font-size:11px;
color:#333333;
border-width: 1px;
border-color: #999999;
border-collapse: collapse;
}
table th {
background:#b5cfd2;
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #999999;
}
table td {
background:#dcddc0;
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #999999;
}
</style>
</head>
<body>
<div id="container4">
<div id="adminpanel">
Admin Page
<div id="showorders"><u>Orders</u></div>
<?php
include('connection.php');
$result = mysql_query("SELECT * FROM orderform");
echo "<table border='1' >
<tr>
<th><u>Date</th>
<th><u>Product</th>
<th><u>Product Comments</th>
<th><u>Name</th>
<th><u>Address</th>
<th><u>Age</th>
<th><u>Delivery</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['date'] . "</td>";
echo "<td>" . $row['product'] . "</td>";
echo "<td>" . $row['productcomments'] . "</td>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['address'] . "</td>";
echo "<td>" . $row['age'] . "</td>";
echo "<td>" . $row['delivery'] . "</td>";
echo "</tr>";
}
echo "</table>";
?>
<div id="showreviews"><u>Reviews</u></div>
<?php
include('connection.php');
$result = mysql_query("SELECT * FROM reviewform");
echo "<table border='1'>
<tr>
<th><u>Name</th>
<th><u>Product</th>
<th><u>Comment</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['product'] . "</td>";
echo "<td>" . $row['comment'] . "</td>";
echo "</tr>";
}
echo "</table>";
?>
</div>
</div>
</body>
这是有问题的两个文件。谢谢你的帮助。就像我之前说的那样,我是一个完整的新手
答案 0 :(得分:2)
将其移至文件顶部:
if (isset($_POST['code']) && $_POST['code'] == '210392') {
header("Location: https://www.google.co.uk");
exit;
}
答案 1 :(得分:0)
如果你这样做是不必要的,你不必检查它的设置。如果您自己检查代码就足够了:
if($_POST['code'] != 210392) {
echo "https://www.google.co.uk";
}
顺便说一句,这不是你所做的错误。您遇到的问题不在此文件中,而是在admin.php
移动上面的if条件,一切都应该可以正常工作,至少在我尝试时它对我有用。