我有我知道可以使用的PHP SESSION变量。但是,当我尝试在它们中回显它们时,它们将不起作用。
我可以用常规代码打印SESSION变量。但是,它们不会显示在以下代码中:
<ul class="nav">
<li class="nav-item dropdown dropdown-hover">
<a class="nav-link dropdown-toggle pr-0" data-toggle="dropdown"
href="#" role="button" aria-haspopup="true" aria-expanded="false">
<i data-feather="user"></i> Hi, <?php echo $first_name; ?>
<i data-feather="chevron-down"></i>
</a>
我向您保证其余的代码都可以使用。我只是不知道如何在上述位置回显$ first_name。
感谢您的帮助。
答案 0 :(得分:2)
尝试此代码。
<ul class="nav">
<li class="nav-item dropdown dropdown-hover">
<a class="nav-link dropdown-toggle pr-0" data-toggle="dropdown"
href="#" role="button" aria-haspopup="true" aria-expanded="false">
<i data-feather="user"></i> Hi, <?php echo $_SESSION['first_name']; ?>
<i data-feather="chevron-down"></i>
</a>
答案 1 :(得分:2)
<?php
session_start();
/*session is started if you don't write this line can't use $_Session global variable*/
$_SESSION["newsession"]=$value;
?>
<?php
session_start();
/*session is started if you don't write this line can't use $_Session global variable*/
$_SESSION["newsession"]=$value;
/*session created*/
echo $_SESSION["newsession"];
/*session was getting*/
?>
<?php
session_start();
/*session is started if you don't write this line can't use $_Session global variable*/
$_SESSION["newsession"]=$value;
/*it is my new session*/
$_SESSION["newsession"]=$updatedvalue;
/*session updated*/
?>
<?php
session_start();
/*session is started if you don't write this line can't use $_Session global variable*/
$_SESSION["newsession"]=$value;
unset($_SESSION["newsession"]);
/*session deleted. if you try using this you've got an error*/
?>
答案 2 :(得分:0)
还请检查您的会话是否开始
您应该使用$ _SESSION ['var_name']; 像$ _SESSION ['first_name'];
或使用提取函数将first_name用作变量。