【发布时间】:2019-10-27 04:22:12
【问题描述】:
在我的 php-header 文档中,我希望能够突出显示用户所在的当前页面,以防止混淆。
问题是,我使用了 if(isset()) 函数来隐藏/显示导航链接,具体取决于用户是否登录。
但是如何突出显示用户点击的页面?我想我必须在 if(isset()) 函数的 php-tags 中的某处包含一些 javascript,然后将其连接到 css 中的活动类,还是我错了?
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>DreamcarZ</title>
<link rel="stylesheet" href="css/style.css" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Ubuntu+Condensed&display=swap" rel="stylesheet">
</head>
<body>
<div class="header">
<div class="topnav">
<div class="logo-container">
<h1>Dreamcar<span>Z</span></h1>
</div>
<?php
if(isset($_SESSION['userId'])){
echo '<a href="index.php">Home</a>
<a href="exclusive_cars.php">Collection</a>
<a href="om_oss.php">About</a>
<a href="#contact">Contact</a>';
}
else {
echo '<a href="index.php">Home</a>
<a href="om_oss.php">About</a>
<a href="#contact">Contact</a>';
}
?>
<div class="login-container">
<?php
if(isset($_SESSION['userId'])){
echo '<form action="includes/logout.inc.php" method="post">
<button type="submit" name="logout-submit">Logout</button>
</form>';
}
else {
echo '<form action="includes/login.inc.php" method="post">
<input type="text" name="mailuid" placeholder="Username...">
<input class="inpt-pwd" type="password" name="pwd" placeholder="Password...">
<button type="submit" name="login-submit">Login</button>
<a class="signup" href="signup.php">Signup</a>
</form>';
}
?>
</div>
</div>
</div>
【问题讨论】: