加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 登录成功后回显用户详细信息

发布时间:2020-12-13 15:59:10 所属栏目:PHP教程 来源:网络整理
导读:呃..现在不行吗? 现在我希望能够扩展我的会话回声,以便我可以添加用户名/全名/等.如果你能告诉我我需要做些什么来添加第二个,我可以弄清楚如何从那里扩展用户价值. 尝试回显用户名,但也可以将其扩展到用户名,名字,姓氏,emp id等的不同页面上…… access.php
呃..现在不行吗?

现在我希望能够扩展我的会话回声,以便我可以添加用户名/全名/等.如果你能告诉我我需要做些什么来添加第二个,我可以弄清楚如何从那里扩展用户价值.

尝试回显用户名,但也可以将其扩展到用户名,名字,姓氏,emp id等的不同页面上……

access.php

<?php
    class Access {      
final public function login( $id,$url = false,$user ) {
        $_SESSION[LOGINSESSION] = $id;

        //you would do this for all columns
        $_SESSION['user'] = $user;

        if ( $url )
            new Redirect(urldecode($url));
        else
            new Redirect(URL);
    }

        final public function require_login() {
            if ( ! self::is_logged(true) )
                self::not_logged();
        }
    }

的index.php

<?php require_once('../admin/pinAPP.php'); $pinAPP = new pinAPP( 'newhire',false,true ); ?>
<?php if ( $pinAPP->can_access() ) { ?><!-- New hire -->
    <center>
        <div class="panel">
                    <div>
                        <br>
                            <b><?= $_SESSION['user']['username']; 
//or
$_SESSION['user']['FirstName']; ?>,</b>
                        <br>
                        <br>
                            <p>Below you will find all the necessary information on needed for onboarding process.</p>                  
                        <br> 
                        <br>
                    </div>
<?php } else {} ?>

<!-- -->

<?php include('footer.php'); ?>

解决方法

更新.您需要在Access :: login方法中设置会话变量来存储该信息.

Access::login(md5($u->username),$_REQUEST['return_url'],$_POST['username']);

将用户名post对象传递给Access :: login方法,然后将方法内的用户名设置为会话变量:

final public function login( $id,$username ) {
        $_SESSION[LOGINSESSION] = $id;
        $_SESSION['username'] = $username;

        if ( $url )
            new Redirect(urldecode($url));
        else
            new Redirect(URL);
    }

然后,您只需在pinAPP页面中调用会话变量:

<?php require_once('../admin/pinAPP.php'); $pinAPP = new pinAPP( 'newhire',true ); ?>
<?php if ( $pinAPP->can_access() ) { ?><!-- New hire -->
    <center>
        <div class="panel">
                    <div>
                        <br>
                            <b><?= $_SESSION['username']; ?>,</b>
                        <br>
                        <br>
                            <p>Below you will find all the necessary information on needed for onboarding process.</p>                  
                        <br> 
                        <br>
                    </div>
<?php } else {} ?>

要将整行传递给函数:

final public function login( $id,$user ) {
        $_SESSION[LOGINSESSION] = $id;

        //you would do this for all columns
        $_SESSION['user'] = $user;

        if ( $url )
            new Redirect(urldecode($url));
        else
            new Redirect(URL);
    }

然后,您将更改索引页以通过以下方式访问该值:

$_SESSION['user']['username']; 
//or
$_SESSION['user']['FirstName'];

你会像这样调用函数:

$userRow = $sql->sqls("UPDATE `". DBPREFIX ."users` SET `last_login_ip` = '". $ip ."',`last_login_timestamp` = '". time() ."' WHERE `username`='$user'");
Access::login(md5($u->username),$userRow);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读