问题描述
我正在为我的学校项目的网站工作.但是我遇到了一个问题.我在每个页面中显示一个标题.我的标题之一包含登录表单,另一个标题包含用户名,搜索栏等.
I am working on website for my school project. But I came across with a problem. I display a header in every page. One of my header contains login form and other one contains username, search bar, etc..
问题是,共有3页;常见问题,联系方式,关于.我想向他们显示用户是否登录.但是标题是有问题的.如果用户未登录,我希望用户看到登录后的标题,否则我想显示header-before-login.
The questions is, there are 3 pages; faq, contact, about. And I want to show them either user is logged in or not. But the headers are problem. I want user to see the header-after-login if user is logged in if not I wanna show header-before-login.
我拥有所有代码.我需要一种方法或一种逻辑来解决此问题.
I have the code any everything. I need a way or a logic to fix this issue.
谢谢.
推荐答案
大概有一百万种方法可以解决此问题,并且我假设您能够以编程方式找出用户是否已登录.
There's probably a million and one ways to solve this, and I'm assuming you're able to programatically find out if the user is logged in.
faq.php,contact.php,about.php:
faq.php, contact.php, about.php:
include 'header.php';
//content
include 'footer.php';
header.php:
header.php:
echo '<!doctype html><html>...';
if($user_is_logged_in == true) {
echo '<body class="logged_in">You are logged in!';
include 'sidebar.php';
} else {
echo '<body class="not_logged_in">You are not logged in!';
include 'user_not_logged_in_header.php';
}
echo '<div class="main">';
footer.php:
footer.php:
echo '</div></body></html>';
sidebar.php:
sidebar.php:
echo '<div class="sidebar">Sidebar!</div>;
然后可以使用这些类独立控制侧边栏div和main div.
Then the sidebar div and main div can be independently controlled using the classes.
这篇关于如何显示标题不同的页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!