How to display pages with different header? [closed]

五迷三道 提交于 2019-12-04 06:24:15

问题


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..

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.

Thank you.


回答1:


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:

include 'header.php';
//content
include 'footer.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:

echo '</div></body></html>';

sidebar.php:

echo '<div class="sidebar">Sidebar!</div>;

Then the sidebar div and main div can be independently controlled using the classes.




回答2:


header();

function header(){
   $header = "<div ";
   if($_SESSION['userID']){
      $header .= "class=\"header user_info_header\"";
      $content = "logged user info";
   }else{
      $header .= "class=\"header login_form_header\"";
      $content = "login form";
   }
   $header .= ">".$content."</div>";
   echo $header; 
}


来源:https://stackoverflow.com/questions/29331890/how-to-display-pages-with-different-header

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!