dryift6733 2013-12-14 04:27
浏览 18

如何在我的网站上创建var然后在另一个页面上显示基于该var的内容?

I'm probably over thinking this, but I have site with various user levels. I'd like to create a specific var (either smarty or in PHP) in my site's header template, then based on this value, display certain code on another page. I've tried several approaches without success. I tried creating a simple function in header.php:

if( $user->level_info.level_name == Basic )
{
$basic_user == yes;
}

Then in video.tpl:

{if $basic_user == yes}
some code
{/if}

It didn't work. I also tried it in smarty (header.tpl)

{if $user->level_info.level_name == Basic}
{assign var="basic_user" value="yes"}
{/if}

Then something like if "var=xx, some code", but honestly I can't even remember how I tried that in video.tpl, but I'm sure it was wrong. Can anyone please help? I'm sure it's simple, but I'm stuck and frustrated. Thanks!

I also just tried this in video.php:

if($user->level_info.level_name != Premium){
header("Location: nopermission.php"); exit();       
} 

And it "works", but all users, no matter if Basic or Premium are forwarded to the no permission page. I am very confused.

  • 写回答

3条回答 默认 最新

  • doujiang6944 2013-12-14 04:42
    关注

    For that, I sometimes use session variables with information of user's role.

    For example:

    $_SESSION['profile'] = 'Basic';
    

    Take a look to session variables. http://www.php.net/manual/en/reserved.variables.session.php

    Remember to resume the session in every page in order to access the variables.

    session_start();
    

    Using your same code, you can do this:

    In header.php:

        if($user->level_info.level_name == Basic){
           session_start();
           $_SESSION['profile'] = 'Basic';
        }
    

    Then in video.tpl:

        session_start();
        if ($_SESSION['profile']=='Basic'){
           //some code
        }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值