检查用户是否登录,是否等于配置文件管理中的名称


Check if user is logged in and equal to the name on profile management

所以我真的不知道我要把这个的标题设置成什么,通常我想不出什么好东西。尽管如此,如果你正在读这篇文章,我会尽我所能在这里解释。

我试图检查当前登录的用户是否等于当前配置文件管理页面上的用户,例如:

当前登录用户:Bob
如果bob正在查看他自己的个人资料页面,他应该看到一个"编辑"按钮,但是,如果他正在查看"Peter"的个人资料页面,他不应该看到。我一直在尝试很多不同的方式,一个我认为会工作的是做一个如果会话等于用户名变量,但没有结果。

我要看的问题是,要么它显示什么都没有,一个空白的页面,到目前为止(除了背景和什么),或鲍勃在例子中使用的访问所有编辑按钮,这是不对的。

还有,我现在所拥有的,如果有什么用的话:

DB连接:

<?php
// error_reporting(E_ALL);
session_start();
$host = 'HOSTNAME';
$dbusername = 'DATABASENAME';
$dbpassword = 'PASSWORD';
$anslutning = mysqli_connect($host, $dbusername, $dbpassword) or die("<b>Could not connect to database server</b>");
$anslutning->select_db('DATABASE NAME') or die("<b>Could not connect to the specified database</b>");

?>

目前的配置文件管理页面:

if(isset($_GET['manage'])) {

                $manage = $_GET['manage'];

                $editAccount = $anslutning->prepare('SELECT userId, username, email, gender, age, profilePic FROM (tablename) WHERE userId=? LIMIT 1');
                $editAccount->bind_param("i", $manage);
                $editAccount->bind_result($userId, $username, $email, $gender, $age, $profilePic);
                $editAccount->store_result();
                $editAccount->execute();
                echo '<h2 class="accountm_title">Account management</h2>';
                if(isset($_SESSION['loggedIn'])) {
                echo '

                <i><a class="edit" href="index.php?editAccount='.$userId.'">Edit</a></i>
                <hr size="1" width="30%" class="manageHr">
                <div class="accountm">
                ';
            }
                while($row = $editAccount->fetch()) {
                    echo '

                    <form action="index.php" method="GET">
                    <p>Username: '.$username.' &nbsp; &nbsp; </p>
                    <p>Email: '.$email.' &nbsp; &nbsp; </p>
                    <p>Gender: '.$gender.'</p>
                    <p>Age: '.$age.' </p>
                    <p>Profile picture: <img src="'.$profilePic.'"></p>
                    </form>
                    ';

            }
        }

然后一些代码更新数据库与字段,这似乎工作。

用户登录系统后,您将有一个会话来存储userId,配置文件页面如下:http://example.com/editAccount=userId只有当会话中的userId等于配置文件页面的userId时,才显示编辑按钮。