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

-=左辺から右の値を引くことを意味します。例えば。

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

それを比較==またはより良いものに変更します===!=/!==を逆の場合に使用することもできます。

于 2013-10-16T10:10:32.057 に答える
0

このようにあなたの状態を変えてください。

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

これを試して:

論理的に正しくないため、if ステートメントを変更するだけです。

これを使って

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

それ以外の

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

ありがとう

于 2013-10-16T10:14:26.777 に答える