How to display pages with different header? [closed]

一曲冷凌霜 提交于 2019-12-02 13:42:54

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.

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