在我的网站中,我需要为所有登录用户管理 CSS。 我需要显示不同的标题颜色,例如蓝色代表一位用户,红色代表另一位用户。
在这里,我动态管理了所有内容,但我无法从应用程序文件夹外部获取已登录的用户类型。这是因为我的动态css页面在style文件夹里面,在CI的application文件夹之外。
我将展示我的一些代码,这可能会有所帮助。
<?php
header("Content-type: text/css; charset: UTF-8");
if($type=="admin")
{
$settingButtonColor = "#990000";
}
if($type=="student")
{
$settingButtonColor = "#990001";
}
if($type=="teacher")
{
$settingButtonColor = "#990002";
}
?>
.sett_btn
{
background-color:<?php echo $settingButtonColor;?> !important;
}
像这样。但是我怎样才能得到那个 session 类型,因为这个变量可以在应用程序文件夹中访问。
有人有什么建议吗?
最佳答案
Function
public function user_type()
{
$userType = $this->session->get_userdata('usertype');
echo $userType;
}
CSS
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://localhost/test/user/user_type');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$type = curl_exec($ch);
curl_close($ch);
header("Content-type: text/css; charset: UTF-8");
if($type=="admin")
{
$settingButtonColor = "#990000";
}
关于php - 如何在 CodeIgniter 3 中访问应用程序文件夹外的登录 session 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41568612/