Display image if variable set to true


#1

I’m making a website for a friend and am wondering about the best way to do something.

It’s a flat site and he wants the ability to disable a banner advert without editing all the pages. I thought the best way to do this is have a file somewhere with a variable set to true then have a bit of php in the

on his site that will only display the ad if this variable is set to true.

Am i right in thinking i can put the following in the top of every page

Code:

<?php include_once('ad_switch.php'); ?>

and then something like the following in the div that holds the banner

Code:

<?php if ($adswitch = true) { image goes here ;} ?>

The problem i’m having is that the image is constantly displaying and i can’t get it to bugger off no matter what the $adswitch variable is set to.

Thanks


#2

Can’t you have the adswitch.php define a variable:

[php]
$myAd = “”;
if ($showAd) { $myAd = “Ad Image Here”; }
[/php]

And include it at the top of all your pages:

[php]include_once “adswitch.php”;[/php]

And then use this to insert the advertisements:

[php]

<?php echo $myAd; ?>

[/php]

Stupid thing … ignore the last ?> after the MoreHTML comment.


#3

That’s great, it’s working, just one really lame question. How would one display the actual image rather than the image location.

Thanks


#4

But that’s HTML, not PHP :wink: