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 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥15 帮我写一个c++工程