【发布时间】:2014-04-18 17:52:34
【问题描述】:
我想显示登录用户的名字。
<div id="userbar">Hello Name. Not you? Log out.</div>
我试过了,但没有用。
<div id="userbar">Hello <?php $_SESSION('log') ?>. Not you? Log out.</div>
【问题讨论】:
我想显示登录用户的名字。
<div id="userbar">Hello Name. Not you? Log out.</div>
我试过了,但没有用。
<div id="userbar">Hello <?php $_SESSION('log') ?>. Not you? Log out.</div>
【问题讨论】:
你忘记了echo
<div id="userbar">Hello <?php echo $_SESSION['log']; ?>. Not you? Log out.</div>
当然,您必须在顶部致电session_start()
【讨论】:
$_SESSION('log') 更正为$_SESSION['log']
<div id="userbar">Hello <?=$_SESSION['log']?>. Not you? Log out.</div>
您还可以检查用户是否已登录,因为如果 $_SESSION['log'] 没有值则会显示错误
<div id="userbar">Hello <?php echo isset($_SESSION['log'])? $_SESSION['log'] :"" ?>. Not you? Log out.</div>
【讨论】:
Php 有不同的打印方法
例子
echo 'this is a simple string';//(single quoted)
echo 'this is a simple string';//double
<?php
$str = <<<EOD
Example of string
spanning multiple lines
using heredoc syntax.
EOD;heredoc
<?php
$str = <<<'EOD'
Example of string
spanning multiple lines
using nowdoc syntax.
EOD;//newdoc
在您的情况下,您可以使用以下任何一种:
echo $_SESSION['log'];
print($_SESSION['log']);
删除 (。$_SESSION 是数组,您可以使用它的索引,例如 $_SESSION['indexname'] DETAIL
【讨论】: