dongpi9164 2017-12-25 15:46 采纳率: 0%
浏览 62
已采纳

PHP用户档案/如果用户有权访问

I wanna ask something about User (who registered) profile settings. For example in many forums you can choose your privacy settings from settings page. I mean "do not show my e-mail address or my name etc.

Let me explain some variables:

$_SESSION['username'] is username whom logged in.

$username : profile page of someone (for example: profile.php/username) - i used get method for this.

I want to show a button if current user(who logged in and viewing someone's profile) has an access to see it or not.

Here we go:

if($_SESSION['username'] != $username)
{
//do not show button
}else{
//show button}

I don't want to use display:none or visibility hidden. Because they can change from source code and i didn't like it. Can i make these settings with private function? I need a solution with examples. Thanks.

  • 写回答

1条回答 默认 最新

  • duanbi1983 2017-12-25 15:55
    关注

    Depends on the logic determining if user has or has not access. If it's just that simple condition comparing two variables, you can simply show the button via echo command:

    if ($_SESSION['username'] === $username) {
        echo '<button>Profile page</button>';
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型