Forum Moderators: coopster

Message Too Old, No Replies

Conditional loading of selected code?

         

encyclo

2:03 am on Oct 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I've got a couple of very basic questions about using PHP to conditionally load content (I'm not a server-side programming expert!). My first question is: what's the best or most simple way in PHP of ensuring that the AdSense code is not invoked when I am viewing a site on a local test server?

Should I make it conditional on the URI? On the test server, the address is "example.dev", as opposed to "example.com" on the live server. Or is there a better way? Ideally, the local server would show a static graphic in the place of the usual ad code.

A secondary (related) query? On the live server, I want to avoid displaying AdSense on specific, pages. I can add a variable such as

$adv="no";
to the pages I want to exclude - is this a good method?

phparion

4:28 am on Oct 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



there can be different methods to do it. You must have found one if you would have tried any. But as you are just thinking so to give you more stuff to think on,

make an Ads class which has different functions for different ads services e.g adsense, MSadcentre, clicksor and your own ads scheme etc.

on testing server check the domain name and make decision which function you are going to call.

now lets do the second part with a little more improvisation.

add "$ad = no" check in your domain IF statement. So it checks domain AND value of $ad in a single IF. on the basis of this IF you can call different functions of your ads class.

jatar_k

12:16 pm on Oct 19, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you could have a double override setup.

A var in a config/included file such as $adv="no"; for the dev site, this would be sitewide, then also have the per page setting as you mentioned.