我已经在我的机器上本地测试了以下脚本,一切都按照我想要的方式完美运行。但是,当我将文件上传到 1and1 的服务器时,在登录脚本上单击“提交”按钮时,它只会停留在登录屏幕上。
我也不确定,但也许问题不在于会话,而在于使用我的标头函数。
<?php
session_start();
require ("login.php");
include ("header.php");
include ("subnav.php");
if ((isset($_SESSION['user'])) && (isset($_SESSION['admin'])))
header('Location: admin/index.php' );
if ((isset($_SESSION['user'])) && (!isset($_SESSION['admin'])))
header('Location: customer/index.php' );
if ((isset($_GET['logout'])) == 1) {
session_destroy();
header('Location: index.php');
}
if (isset($_POST['submit']))
if($_POST['username'] == 'jay') {
$_SESSION['user'] = 'jay';
$_SESSION['admin'] = 1;
header('Location: admin/index.php' );
}
else if ($_POST['username'] == 'william'){
$_SESSION['user'] = 'william';
header('Location: customer/index.php' );
}
else {
header('Location: http://www.google.com' );
}
?>
<h2>System Log-In</h2>
<form action="" method="post">
<ul id="login">
<li>
Username: <br>
<input type="text" name="username"></li>
<li>
Password: <br>
<input type="password" name="password">
</li>
<li>
<input type="submit" value="Log-In" name ="submit" id="submit">
</li>
<li>
<br><a href=#>Register Here.</a>
</li>
<li>
If you are having problems with the log-in process, please send us an <a href="mailto:here@here.us">e-mail</a>.
</li>
</ul>
</form>
<?php
include ("footer.php");
?>