0

I've been trying to conditionally include a banner which incorporates a form into a php site. Previously the banner was part of the header but I need to exclude it from certain pages in order for other elements to be included.

I'm using $_SERVER['SCRIPT_NAME'] to define a variable on the page and then check for this. I'm a little confused though as to where the variable should be placed. Will it work if placed in the header or does it need to be included in every separate page?

This is what I've got:

<?php $currentPage = $_SERVER['SCRIPT_NAME']; ?>    
<?php if ($currentPage != "/ecoProcess.php") {
include ("includes/banner.php");
 } else {
echo "ECO";
 }
 ?>

For further info, I've updated the code because of my schoolboy error with -= instead of != but neither of the conditions works now (no banner, no "ECO"). The pages are being called using this method:

    <?php if($_GET['action']=='boiler_installation_replacement') {?> class="active"<? php } ?>><a href="index.php?action=boiler_installation_replacement&src=<?php echo $_GET['src']; ?>">Boiler Installation and Replacement</a>

I've been advised to try var_dump which reveals this:

' string(14) "/ths/index.php" ' everytime. I guess this is due to the way the pages are called but I don't know how to get around this.

4

3 回答 3

0

像这样改变你的条件。

<?php 
 $currentPage = $_SERVER['SCRIPT_NAME'];     
 if ($currentPage == "/ecoProcess.php") {
     include ("includes/banner.php");
 } else {
    echo "ECO";
 }
 ?>
于 2013-10-16T10:08:14.480 回答
0

-=表示从左边减去右边的值。例如。

$a = 5;
$a -= 3;
echo $a; // will print 2 because 5 - 3 = 2 :)

将其更改为比较==或更好===。您也可以将!=/!==用于相反的情况。

于 2013-10-16T10:10:32.057 回答
0

尝试这个:

只需更改您的 if 语句,因为它在逻辑上不正确。

用这个

if ($currentPage == "/ecoProcess.php")

代替

if ($currentPage -= "/ecoProcess.php")

谢谢

于 2013-10-16T10:14:26.777 回答