Title: How To Serve Text-Link and Image Ads With PHP
Author: LeeDavis
Category: CODING
Published: 2017-02-19 15:36:04
Clicks: 115

I'm not fond of having to include third-party ads from a purely programmatic standpoint. Network latency is one of the main gremlins that comes to mind when trying to reduce load-in page speeds. And it's one of the main reasons why I don't include many ads in current sites. And when you factor in the irrational fear of JavaScript, you begin to understand why there is abundant reticence on the part of many site owners currently. I've been loathe to either include ad-server content (holding back your page from loading before ads do), or JavaScript-based ad-service. But, as the former owner of a PayPal™-enabled shopping cart, I had to search for ways to link to products there in the old article directory to give them more visibility.

Front Door Of The Old Cartdrone Site

As usual, PHP to the rescue! I found a simple way to rotate both text-link or image ads, and differently than previous methods I investigated. Now, I was able to stack a group of ads together, and then, with each refresh of the page, have a different ad in place. There's no need for even an ad server with this coding solution, since as ads grow in amount over time, they can be called via a PHP "include" statement so the size of the file doesn't interfere with your page load;


$num = Rand (1,3);
switch ($num)
{
case 1:
echo '

\r\n<>br />

Sample Link
Illustration Of Embedded Link
 

';
break;
case 2:
echo '

\

Sample Link
Illustration Of Embedded Link
 

';
break;
case 3:
echo '
'
}
?>
PHP Rotation Coding Sample

In the above example, you have a tabular setup for the first two ads, and then an example of an image link, which can have a text link substitute by removing the "img src" part. Try this PHP coding technique where you don\'t want to use JS, but you want to be able to circulate ads on the page without taking up space.