我正在尝试在 PHP 上使用 $_SESSION 超全局来验证用户,但似乎 $_Session 不喜欢我任何帮助都非常感谢,我有以下名为 index.php 的代码:
'<?php
'session_start();
'require("administratorcheck.php");
//i have tried require_once "administratorcheck.php"
'?>
在这种情况下,administratorcheck.php 看起来像这样用于验证:
<?php
$errorMessage = 'Your Login Information Is Not Correct';
if(isset($_POST['username'])){
$username = $_POST['username'];
$password = $_POST['password'];
$adminUser = "admin";
$adminPass = "donkeyKong";
if(($username!=$adminUser)||($password !=$adminPass))
{
echo $errorMessage;
}else{
// session_register('admin');
$_SESSION['admin'] = $username;
header("index.php");
exit();
}
}
if(isset($_SESSION['admin'])!= 'admin')
{
echo '<h2>You Are Not Authorized To View This File</h2><br/>
<table width = "400" border = "2">
<form action = "administratorcheck.php" method="post" >
<tr>
<td colspan = "2">You May Be Able To Login Here</td>
</tr>
<tr>
<td width="108">Admin Username:</td>
<td width="250"><input type="text" name="username" id="username" style="width:98%"/>
</td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="password" id="password" style="width:98%"/></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="button" id="button"
value="Log Me In"/></td>
</tr>
</form>
</table>
</br>
</br>
<a href = "../">Click Here To Return To The Index Page</a>';
exit();
}
?>