如何使php页脚不出现在我网站的特定页面上?

时间:2019-06-07 14:46:20

标签: php html

我正在尝试将网页从代码中排除到网页之外,并且想不出能够实现此目的的功能。

'''

include "header.php";

if ($_GET['page'] == ""){
    echo "<meta http-equiv='refresh' content='0; URL=/?page=home' />";
}else{
    $page = $_GET['page'];
    include $page.".php";
}

include "footer.php";

if ($GET['page'] == "handyman.php"){

}

'''

我只希望此页面不显示页脚。任何方向将不胜感激!

3 个答案:

答案 0 :(得分:0)

在不需要页脚的页面上进行负性测试。

if ($_GET['page'] != '"handyman'){
    include "footer.php";
}

答案 1 :(得分:0)

您的代码应如下所示。

include "header.php";

if ($_GET['page'] == ""){
    echo "<meta http-equiv='refresh' content='0; URL=/?page=home' />";
}else{
    $page = $_GET['page'];
    include $page.".php";
}

if ($_GET['page'] <> "handyman.php"){
      include "footer.php";   
}

答案 2 :(得分:0)

您可以使用Query StringParse_StrSwitch来确保安全,位于期望的结果下方:

<?php
  ini_set('default_charset', 'UTF-8');
  $gurl = $_SERVER['QUERY_STRING'];
  $ourl = array();
  parse_str($gurl, $ourl);
  if (isset($ourl['page']) || (!empty($ourl['page']))) {
    $page = htmlspecialchars($ourl['page'], ENT_QUOTES, 'UTF-8');
    switch ($page) {
      case 'register':
        include("header.php)";
        include("register.php");
        include("footer.php");
      break;
      case 'signup':
        include("header.php)";
        include("signup.php");
        include("footer.php");
      break;
      case 'login':
        include("header.php)";
        include("login.php");
        include("footer.php");
        break;
      case 'handyman':
        include("header.php)";
        include("handyman.php");
        #include("footer.php"); // footer not included
        break;
      default:
        include("header.php)";
        include("home.php");
        include("footer.php");
    }
  } else {
    exit("No available options...");
  }
?>

未经测试即时编写...使用非常简单:

your_page.php?page=handyman

your_page.php?page=register

your_page.php?page=etc...