简体   繁体   中英

PHP include unless on a certain page, then include different

I have a php site that includes a menu. There is a section that I do not want to include that menu, but want to include a different one. I am sure I need an if/else but am struggling.

my index is built like this
html and head
div wrapper
include header
include page build
include footer

the page build file uses the index template and calls for each pages content. therefore each page uses the same header and footer. i want to use a second header on a specific section.

so section 1, 3, 4, 5, 6, 7, 8 uses header 1
section 2 uses header 2

say, you have a file called menu.php which you want to include in index.php and in that menu you do not want to include a menu/text called Loggin . Ok? Now, in menu.php you can do like this:

<p> Home </p><p> about</p><p> profile</p><p> blog</p><?php if(isset($allow)) {echo '<p> Loggin</p>';} else {echo "";}

With the above if/else you are telling PHP, if the variable $allow has any value echo Loggin, else show nothing. now all you have to do, is include your menu, but in index.php either set $value to anything if you want Loggin to be shown, or just leave it if you don't want loggin to not appear

You could try using:

if ($_SERVER['SCRIPT_NAME'] == "/page1.php") {
    include("fileToInclude.php");
} else {
    include("differentFileToInclude.php");
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM