new ad module

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: new ad module

Post by Vegan »

I was thinking myself of using the embedded echo as the only variant part is the ASIN which is the product number

thanks everyone for the suggestions and code samples

this thread is sure to benefit a lot of visitors if nothing else, as to how to monetize a lot of hard work
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: new ad module

Post by Vegan »

I have tried you module, seems it causes my ads and 1/2 the page to disappear

something is not working so back to the drawing board

Code: Select all

<?
class AdFactory {

        protected $ads = array(
                //    used,  HTML
                array(false, '<iframe src="http://rcm.amazon.com/e/cm?lt1=_blank&bc1=000000&IS2=1&bg1=FFFFFF&fc1=000000&lc1=0000FF&t=cpa07-20&o=1&p=8&l=as4&m=amazon&f=ifr&ref=ss_til&asins=B0062U5KG6" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe>'),
                array(false, '<iframe src="http://rcm.amazon.com/e/cm?lt1=_blank&bc1=000000&IS2=1&bg1=FFFFFF&fc1=000000&lc1=0000FF&t=cpa07-20&o=1&p=8&l=as4&m=amazon&f=ifr&ref=ss_til&asins=B0076DO5A0" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe>'),
                array(false, '<iframe src="http://rcm.amazon.com/e/cm?lt1=_blank&bc1=000000&IS2=1&bg1=FFFFFF&fc1=000000&lc1=0000FF&t=cpa07-20&o=1&p=8&l=as4&m=amazon&f=ifr&ref=ss_til&asins=B0053BSMPQ" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe>'),
                array(false, '<iframe src="http://rcm.amazon.com/e/cm?lt1=_blank&bc1=000000&IS2=1&bg1=FFFFFF&fc1=000000&lc1=0000FF&t=cpa07-20&o=1&p=8&l=as4&m=amazon&f=ifr&ref=ss_til&asins=B005THAX60" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe>'),
                array(false, '<iframe src="http://rcm.amazon.com/e/cm?lt1=_blank&bc1=000000&IS2=1&bg1=FFFFFF&fc1=000000&lc1=0000FF&t=cpa07-20&o=1&p=8&l=as4&m=amazon&f=ifr&ref=ss_til&asins=B002I0KOSI" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe>'),
                array(false, '<iframe src="http://rcm.amazon.com/e/cm?lt1=_blank&bc1=000000&IS2=1&bg1=FFFFFF&fc1=000000&lc1=0000FF&t=cpa07-20&o=1&p=8&l=as4&m=amazon&f=ifr&ref=ss_til&asins=B0050SZ0SY" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe>'),
                array(false, '<iframe src="http://rcm.amazon.com/e/cm?lt1=_blank&bc1=000000&IS2=1&bg1=FFFFFF&fc1=000000&lc1=0000FF&t=cpa07-20&o=1&p=8&l=as4&m=amazon&f=ifr&ref=ss_til&asins=B007FTE2VW" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe>'),
                array(false, '<iframe src="http://rcm.amazon.com/e/cm?lt1=_blank&bc1=000000&IS2=1&bg1=FFFFFF&fc1=000000&lc1=0000FF&t=cpa07-20&o=1&p=8&l=as4&m=amazon&f=ifr&ref=ss_til&asins=B0050SWTS8" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe>')
                // array(false, 'insert ad 1 here'),
                // array(false, 'insert ad 2 here')
        );
        protected $uniqueremaining;

        public function __construct() {
                $this->uniqueremaining = count($this->ads);
        }

        public function addAd($html) {
                $this->ads[] = array(false, $html);
                $this->uniqueremaining++;
        }

        public function getAd() {
                return $this->ads[mt_rand(0, count($this->ads) - 1)][1];
        }

        public function getUniqueAd($fallback = false) {
                if ($this->uniqueremaining == 0) {
                        return ($fallback ? $this->getAd() : false);
                }
                $n = mt_rand(1, $this->uniqueremaining);
                foreach ($this->ads as $key => $ad) {
                        if (!$ad[0] && --$n == 0) {
                                $this->ads[$key][0] = true;
                                return $ad[1];
                        }
                }
        }
        public function getMultipleAds($number) {
                $ads = array();
                foreach (array_rand($this->ads, $number) as $key) {
                        $ads[] = $this->ads[$key][1];
                }
                return $ads;
        }
}
?>

<div class="float-right" style="width: 500px; text-align: center">

<? // now its possible to conjure up the actual ad
$factory = new AdFactory;
$ad = $factory->getUniqueAd();
echo $ad
$ad = $factory->getUniqueAd();
echo $ad
$ad = $factory->getUniqueAd();
echo $ad
$ad = $factory->getUniqueAd();
echo $ad
$ad = $factory->getUniqueAd();
echo $ad
$ad = $factory->getUniqueAd();
echo $ad
$ad = $factory->getUniqueAd();
echo $ad
$ad = $factory->getUniqueAd();
echo $ad
?>
</div>
what is happening is that the class declaration is being echoed which is bizzare, it should not be expressed at all

my pages are made up of components, some use php successfully

Code: Select all

<?php 

$href = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];

?>

<div class="fb-like" data-href="http://www.hardcore-games.tk/" data-send="false" data-width="450" data-show-faces="false"></div>
<br>
<br>

<!-- Copyright -->
<footer>
&copy; 583727 BC LTD, All Rights Reserved. <a href="http://www.hardcore-games.tk/about/legals.php">Legals</a>.&nbsp;  
<?php echo "Last modified: " . date ("F d, Y (H:i:s)", getlastmod()); ?>
</footer>
<br>

<div class="centered">
	<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
		<input type="hidden" name="cmd" value="_s-xclick">
		<input type="hidden" name="hosted_button_id" value="GVJSYJ6KBVN4C">
		<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_subscribeCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
		<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
	</form>
</div>
<br>
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: new ad module

Post by Vegan »

for some reason the document is being truncated categorically and its not logical as the entire code base is consistent
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: new ad module

Post by Vegan »

now I am over here with javascript which does not seem to be so buggy

viewtopic.php?f=13&t=136898
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: new ad module

Post by Christopher »

Vegan wrote:I have tried you module, seems it causes my ads and 1/2 the page to disappear
I just typed the code in -- not tested. Causing half the page to disappear just sounds a HTML open/close problem...
(#10850)
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: new ad module

Post by Vegan »

i now have a functional JavaScript solution

in essence I take the table of ads, shuffle and then deal off the desired number off the top

Code: Select all

// Fisher-Yates shuffle model
function shuffle(array) {
  	var m = array.length, t, i;
   	while (m) { // While there remain elements to shuffle…
	    i = Math.floor(Math.random() * m--); // Pick a remaining element…
	    t = array[m]; // And swap it with the current element.
	    array[m] = array[i];
	    array[i] = t;
	  }
  	return array;
}

function showads(number) {
	var i;
	shuffle(amazonads); // shuffle the ads so that a linear selection is randomized
	for (i=0; i<number; i++) {
		temp = '<iframe src="http://rcm.amazon.com/e/cm?lt1=_blank&bc1=000000&IS2=1&bg1=FFFFFF&fc1=000000&lc1=0000FF&t=cpa07-20&o=1&p=8&l=as4&m=amazon&f=ifr&ref=ss_til&asins=';
		temp += amazonads[i];
		temp += '" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe>';
		document.write(temp+='\n');
	}
}
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: new ad module

Post by Vegan »

errors have been a real nuisance to achieving the desired outcome
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: new ad module

Post by Christopher »

I tried the code I posted, and besides having to create the $adModel object and fixing the typo changing the name of $data to $ad -- it seemed to work fine. I get N unique ads in frames. Maybe I am not clear about what you want?
(#10850)
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: new ad module

Post by Vegan »

I have got the JavaScript working so my goal of random game offerings is now operational.

I looked hard at the PHP version, and I wonder if my JS strategy might be better than the class angle?

shuffle is easy enough (I took stats in school among other useful courses), analysis shows it to be tolerant of crappy random number generators too
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: new ad module

Post by Vegan »

With a pool of over 60 games, now I can guarantee any page can have unique ads for a block ad

this topic is definitely a candidate for cleanup and sticky, topic web site monetization
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: new ad module

Post by Vegan »

seems my new ad tool has already achieved positive results, games sales are up sharply

google seems to like my gaming site, traffic keep going up up and up
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
Post Reply