gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 07:39:07 24 4
gpt4 key购买 nike

呃..现在它不工作了?

现在我希望能够扩展我的 session 回显,以便我可以添加用户名/全名/等等。如果你能告诉我我需要做什么来添加第二个,我就能弄清楚如何从那里扩展用户值(value)。

尝试回显用户名,但也能够将其扩展到用户名、名字、姓氏、emp id 等的不同页面上......

访问.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();
}
}

索引.php

    <?php require_once('../admin/pinAPP.php'); $pinAPP = new pinAPP( 'newhire', false, 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 方法中设置一个 session 变量来存储该信息。

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

将用户名 post 对象传递给 Access::login 方法,然后在该方法中将该用户名设置为 session 变量:

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

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

然后你只需在你的pinAPP页面中调用一个session变量:

 <?php require_once('../admin/pinAPP.php'); $pinAPP = new pinAPP( 'newhire', false, false, 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, $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);
}

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

$_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), $_REQUEST['return_url'],$userRow);

关于php - 登录成功后回显用户详细信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33727975/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com