每次刷新页面时,用户都会注销并重定向到index.php
。我猜测我还没有正确设置会话变量。我在本地工作得很好,但没有把它移到临时服务器上。
处理登录的文件。如果需要,我可以从其他文件发布代码:
<?php
session_start();
include('global.php');
if(isset($_POST["login"])) {
$email = db_quote($_POST['email']);
$password = db_quote($_POST['password']);
$type = db_quote($_POST['timesheettype']);
$_SESSION['login'] = "";
if(empty($_POST['email']) || empty($_POST['password'])) {
phpAlert("Please complete all form fields");
echo "<script>window.location.href = '../timesheetmanager/index.php';</script>";
}
else {
$query = db_select("SELECT * FROM timesheetlogin WHERE email = {$email} AND password = {$password}");
if($query == false) {
phpAlert("Sorry those details are incorrect.");
echo "<script>window.location.href = 'index.php';</script>";
}
else {
$_SESSION['login'] = $query[0]["id"];
header ("Location: main.php");
}
}
}
main.php中的代码
<?php
session_start();
//$query = $_SESSION['login'];
$id = $_SESSION['id'];
$type = $_SESSION['type'];
$name = $_SESSION['name'];
include('header.php');
echo $_SESSION['id'];
?>
<div class="content grid-70">
<h2>Timesheet Manager Home</h2>
<?php
if ($type == "cand") {
$tscandquery = db_select("SELECT * FROM timesheets WHERE candid={$id} AND status=\"cand\"");
$tsclientquery = db_select("SELECT * FROM timesheets WHERE candid={$id} AND status=\"client\"");
$tscandresult = count($tscandquery);
$tsclientresult = count($tsclientquery);
$_SESSION['tscandresult'] = $tscandresult;
$_SESSION['tsclientresult'] = $tsclientresult;
if($tscandresult == "0" && $tsclientresult == "0") { ?>
<p>All of your timesheets are up to date</p>
<?php }
if($tscandresult != "0") { ?>
<p>You currently have <?php echo $tscandresult; ?> timesheets awaiting your submission</p>
<a href="timesheets/candidate-list.php">View your Active Timesheets</a>
<?php }
if($tsclientresult != "0") { ?>
<p>You currently have <?php echo $tsclientresult; ?> timesheets awaiting supervisor's approval.</p>
<?php }
}
if ($type == "client") {
$tscandquery = db_select("SELECT * FROM timesheets WHERE clientid={$id} AND status=\"cand\"");
$tsclientquery = db_select("SELECT * FROM timesheets WHERE clientid={$id} AND status=\"client\"");
$tscandresult = count($tscandquery);
$tsclientresult = count($tsclientquery);
$_SESSION['tscandresult'] = $tscandresult;
$_SESSION['tsclientresult'] = $tsclientresult;
if($tscandresult == "0" && $tsclientresult == "0") { ?>
<p>All of your timesheets are up to date</p>
<?php }
if($tscandresult != "0") { ?>
<p>You currently have <?php echo $tscandresult ?> timesheets awaiting candidate submission</p>
<?php }
if($tsclientresult != "0") { ?>
<p>You currently have <?php echo $tsclientresult; ?> timesheets awaiting your approval</p>
<a href="timesheets/client-list.php">View Timesheets awaiting approval</a>
<?php }
} ?>
</div>
<div class="grid-30 no-padding">
<?php
include('rh-nav.php');
?>
</div>
</div>
<?php
include('footer.php');
?>