大家好我已經做了研究,我似乎無法弄清楚我的代碼在做什麼。我知道會話變量應該改變,除非改變它們或刪除它們。我不認爲這個問題是特定於瀏覽器的後退按鈕,因爲當訪問另一個頁面時,它似乎不工作,它只是在家中工作到另一個頁面,但當我訪問另一個頁面時,它不會似乎工作。會話變量,類和後退按鈕
我正在建立一個自定義CMS(必須是自定義的,我已經思考了所有其他選項)我基本上正在做一個訪問控制腳本。首先,我試圖通過將會話中的用戶角色或用戶類型作爲變量進行存儲,但在按回或進入第三個頁面時不起作用。該變量用於根據用戶類型顯示菜單鏈接。
這是我檢查我的會議
$now=time();
if (!isset($_SESSION)) {
session_start();
}
if (!isset($_SESSION['session_user_name']) || $now - $_SESSION['session_start']>60*60){
header('Location:login.php');
exit;
}else{
//$user_name = $_SESSION['session_user_name'];
//$user_type = $_SESSION['session_user_type'];
}
require(CMS_ROOT.'/classes/acl.php');
$user_role = new ACL();
$user_type = $user_role->userRole;
這是我的ACL類
class ACL
{
var $userID = 0; //Integer : Stores the ID of the current user
var $userRole = ''; //String : Stores the roles of the current user
function __constructor($userID = '')
{
if ($userID != '')
{
$this->userID = floatval($userID);
} else {
$this->userID = floatval($_SESSION['session_user_id']);
}
$this->userRole = $this->getUserRole();
}
function ACL($userID='')
{
$this->__constructor($userID);
}
function getUserRole()
{
global $table_prefix;
$user_id = $this->userID;
$strSQL = "SELECT user_type FROM ${table_prefix}users WHERE user_id = $user_id" ;
$data = mysql_query($strSQL) or die(mysql_error());
$resp = 'null';
$row = mysql_fetch_assoc($data);
$resp = $row['user_type'];
return $resp;
}
}
,這是菜單
<nav>
<ul>
<?php echo $user_type; if($user_type == 'administrator' || $user_type == 'manager'){?>
<li><a href="<?php echo $cms_path; ?>/index.php">Home</a></li>
<? } ?>
<?php if($user_type =='administrator' || $user_type == 'manager'){?>
<li><a href="<?php echo $cms_path; ?>/users/user_view.php" >Users</a></li>
<? } ?>
<?php if($user_type == 'administrator' || $user_type == 'manager'){?>
<li><a href="<?php echo $cms_path; ?>/clients/client_view.php" >Clients</a></li>
<? } ?>
<li><a href="<?php echo $cms_path; ?>/albums/album_view.php" >Albums</a></li>
<li><a href="<?php echo $cms_path; ?>/logout.php">logout</a></li>
</ul>
</nav>
我希望有人能幫助或引導我在正確的方向。
正如一個建議,我會建議不要在這裏重新發明輪子,而應該使用完善的框架(Laravel是我的最愛 - http://laravel.com/docs/5.1),並利用預先構建的用戶管理庫(如泄密https://github.com/Zizaco/confide)。有這麼多的安全細微差別,建立一個堅實的認證系統,這些圖書館可以脫下你的盤子 –
我不明白你的問題是什麼。我知道你嘗試在會話中添加一個變量,但它不起作用。你序列化了嗎?另外,你在評論'$ userID'是一個整數,但是在你使用'floatval()'之後的一些行是整數還是浮點數? –
@Jonathan Crowe這是一個定製的服務解決方案,所以它必須儘可能的定製。它會像wordpress一樣在一個框架上構建wordpress。我們需要儘可能多地控制代碼,而不能依賴於框架在可預見的將來是否處於積極的發展和支持之下,這將影響整個商業理念。 –