我是新來的PHP,在我的學生結果在線系統中完成我的最後一年項目。會話不能正常工作,刷新頁面時會丟失自動會話或內容丟失頁面
在我的系統中,我在會話中出現錯誤,一旦用戶/學生使用他們的用戶名和密碼登錄,儀表板會正確顯示他的詳細信息。
但是,只要頁面重新加載或您點擊查看其他內容或者只是簡單地點擊儀表板內的學生工具欄,該頁面就會丟失其所有相關內容並變爲空閒或空白。
我想防止自動會話破壞或丟失,而用戶仍然在同一頁面上,直到他/她註銷。任何幫助將不勝感激。有趣的是,這些代碼在Localhost(Wamp Server)中運行得非常好,但它在Online(cpanel)中丟失了會話。
我的代碼頁是: 的login.php
<?php
include('dbcon.php');
if (isset($_POST['login'])){
session_start();
$student_no = $_POST['student_no'];
$password = $_POST['password'];
$query = "SELECT * FROM students WHERE student_no='$student_no' AND password='$password' and status = 'active' ";
$result = mysql_query($query)or die(mysql_error());
$num_row = mysql_num_rows($result);
$row=mysql_fetch_array($result);
if($num_row > 0) {
header('location:dasboard.php');
$_SESSION['id']=$row['student_id'];
}
elae{
header('location:access_denied.php');
}
}
?>
session.php文件
<?php
session_start();
if (!isset($_SESSION['id']) || (trim($_SESSION['id']) == '')) {
header("location: index.php");
exit();
}
$session_id=$_SESSION['id'];
?>
dasboard.php
<?php include('session.php'); ?>
<?php include('header.php'); ?>
<?php include('navbar.php'); ?>
<?php
$query=mysql_query("select * from students where student_id='$session_id'")or die(mysql_error());
$row=mysql_fetch_array($query);
$year_level = $row['year_level'];
$term = $row['term'];
$status = $row['student_status'];
$school_year = $row['year_level'];?>
<div class="container">
<div class="margin-top">
<div class="row">
<?php include('head.php'); ?>
<div class="span12">
<div class="grade">
<?php include('grade_option.php'); ?>
</div>
</div>
<div class="span2">
<?php include('user_sidebar.php'); ?>
</div>
<div class="span10">
<table cellpadding="0" cellspacing="0" border="0" class="table table-bordered" id="example">
<thead>
<tr>
<th width="100">Code</th>
<th width="300">Subject</th>
<th width="50">Units</th>
<th>Gen Ave.</th>
<th>Term</th>
<th>Year Level</th>
<th>Remarks</th>
</tr>
</thead>
<tbody>
<?php $user_query=mysql_query("select * from grade where student_id = '$session_id' and school_year = '$year_level'
and semester = '$term'
")or die(mysql_error());
while($row=mysql_fetch_array($user_query)){
$id=$row['grade_id'];
$remarks = $row['remarks'];
$subject_id = $row['subject_id'];
$subject_query = mysql_query("select * from subject where subject_id = '$subject_id'")or die(mysql_error());
while($subject_row=mysql_fetch_array($subject_query)){
?>
<tr>
<td>
<?php echo $subject_row['code']; ?></td>
<td><?php echo $subject_row['title']; ?></td>
<td><?php echo $subject_row['unit']; ?></td>
<td><?php echo $row['gen_ave']; ?></td>
<td><?php echo $row['semester']; ?></td>
<td><?php echo $row['school_year']; ?></td>
<?php if ($remarks == 'Very Good'){ ?>
<td><span class="very_good"><?php echo $row['remarks']; ?></span></td>
<?php }else if($remarks == 'Excellent'){ ?>
<td><span class="Excellent"><?php echo $row['remarks']; ?></span></td>
<?php }else if($remarks == 'Satisfactory'){ ?>
<td><span class="sat"><?php echo $row['remarks']; ?></span></td>
<?php }else if($remarks == 'Fair'){ ?>
<td><span class="fair"><?php echo $row['remarks']; ?></span></td>
<?php }else if($remarks == 'Failed'){ ?>
<td><span class="failed"><?php echo $row['remarks']; ?></span></td>
<?php }else if($remarks == 'Incomplete'){ ?>
<td><span class="failed"><?php echo $row['remarks']; ?></span></td>
<?php }else if($remarks == 'Officially Dropped'){ ?>
<td><span class="drop"><?php echo $row['remarks']; ?></span></td>
<?php }else if($remarks == 'PASS'){ ?>
<td><span class="Excellent"><?php echo $row['remarks']; ?></span></td>
<?php }else if ($remarks == ''){ ?>
<td><?php echo $row['remarks']; ?></td>
<?php } ?>
</tr>
<?php }} ?>
</tbody>
</table>
</div>
<?php include('units_table.php'); ?>
<?php include('gwa_table.php'); ?>
<?php include('cwa_table.php'); ?>
</div>
<?php include('grading_system.php') ?>
</div>
</div>
</div>
<?php include('footer.php') ?>
請使用最新的代碼更新您的問題中的login.php腳本。當試圖找出錯誤發生的位置時,會產生混淆。另外,包含'var_dump($ _ SESSION,$ session_id);在'session.php'結尾處,並且在header.php中的$ query之前,順便說一句,如果您將它稱爲'$ _SESSION ['student_id']',那麼稍後您就會更容易混淆。 –
你可以檢查,我發現這個代碼內的問題從dasboard.php頁面: <?php $ query = mysql_query(「select * from students where student_id ='$ session_id'」)或死(mysql_error()) ; $ row = mysql_fetch_array($ query); $ year_level = $ row ['year_level']; $ term = $ row ['term']; $ status = $ row ['student_status']; $ school_year = $ row ['year_level']; ?> 我認爲,我必須設置cookie來存儲會話在dasboard.php的某個地方,但我不知道。如果可以的話,會很棒。如果我收到你的電子郵件,我可以給你發鏈接,看看有什麼確切的錯誤?! –
我可以聯繫的電子郵件地址可以在這裏找到[Pastebin](http://pastebin.com/1taYrDSA)。它非常公開,但每隔幾個小時就會刪除任何電子郵件。 –