我试图创建一个主管理页面,我可以通过用户名来问候用户,' Hello [用户名]',用户名突出显示。我的问题是Hello [username]也突出显示后的任何标签。如何从其他标签中删除高光?
的index.php
<?php
require_once 'core/init.php';
if(Session::exists('home')) {
echo '<p>' . Session::flash('home'). '</p>';
}
$user = new User(); //Current
if($user->isLoggedIn()) {
?>
<?php include("layout/adminheader.php");?>
<?php include("layout/adminNav.php");?>
<p>Hello, <a href="profile.php?user=<?php echo escape($user->data()- >username);?>"><?php echo escape($user->data()->username); ?></p>
<h6>TEST</h6>
<?php } ?>
的init.php
<?php
session_start();
$GLOBALS['config'] = array(
'mysql' => array(
'host' => 'localhost',
'username' => 'secret',
'password' => 'secret',
'db' => 'db'
),
'remember' => array(
'cookie_name' => 'hash',
'cookie_expiry' => 604800
),
'sessions' => array(
'session_name' => 'user',
'token_name' => 'token'
)
);
spl_autoload_register(function($class) {
require_once 'classes/' . $class . '.php';
});
require_once 'functions/sanitize.php';
if(Cookie::exists(Config::get('remember/cookie_name')) && !Session::exists(Config::get('sessions/session_name'))) {
$hash = Cookie::get(Config::get('remember/cookie_name'));
$hashCheck = DB::getInstance()->get('users_session', array('hash', '=', $hash));
if($hashCheck->count()) {
$user = new User($hashCheck->first()->user_id);
$user->login();
}
}
功能页面
public function isLoggedIn() {
return $this->isLoggedIn;
}
答案 0 :(得分:2)
您似乎忘记在index.php文件中关闭标记。
在index.php中查找以下行:
<p>Hello, <a href="profile.php?user=<?php echo escape($user->data()- >username);?>"><?php echo escape($user->data()->username); ?></p>
并改变它
<p>Hello, <a href="profile.php?user=<?php echo escape($user->data()- >username);?>"><?php echo escape($user->data()->username); ?></a></p>