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.

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>';
}