Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

Rotate YPN and AS with Phpadsnew

some problems



12:25 am on Feb 1, 2006 (gmt 0)

5+ Year Member


I was trying to install phpadsnew and got through the part where i can rotate between google adsense and ypn ads. However, i noticed that when i am using the remote invocation for javascript type, i can't get the real javascript source pulled up from the source file, means when i view the source file of the page, it is showing something ;like this:-

<script language='JavaScript' type='text/javascript' src='http://www.mysite.com/phpadsnew/adx.js'></script>
<script language='JavaScript' type='text/javascript'>
if (!document.phpAds_used) document.phpAds_used = ',';
phpAds_random = new String (Math.random()); phpAds_random = phpAds_random.substring(2,11);

document.write ("<" + "script language='JavaScript' type='text/javascript' src='");
document.write ("http://www.mysite.com/phpadsnew/adjs.php?n=" + phpAds_random);
document.write ("&amp;what=zone:3&amp;withText=1");
document.write ("&amp;exclude=" + document.phpAds_used);
if (document.referrer)
document.write ("&amp;referer=" + escape(document.referrer));
document.write ("'><" + "/script>");
</script><noscript><a href='http://www.mysite.com/phpadsnew/adclick.php?n=a35a85bd' target='_blank'><img src='http://www.mysite.com/phpadsnew/adview.php?what=zone:3&amp;n=a35a85bd' border='0' alt=''></a></noscript>

That's why i was wondering whether this is allowed per TOS? Because i can't seem to view the javascript pulled from ypn or adsense server.

In fact, if i use the local mode for phpadsnew, i can see real javascript source code being pulled out like this:-

<script language="JavaScript" type="text/javascript">
ctxt_ad_partner = "myypnadcode";
ctxt_ad_section = "";
ctxt_ad_bg = "";
ctxt_ad_width = 250;
ctxt_ad_height = 250;
ctxt_ad_bc = "000000";
ctxt_ad_cc = "000000";
ctxt_ad_lc = "FFFFFF";
ctxt_ad_tc = "FFFFFF";
ctxt_ad_uc = "FFFFFF";
// -->
<script language="JavaScript" src="http://ypn-js.overture.com/partner/js/ypn.js">
</script><div id="beacon_4" style="position: absolute; left: 0px; top: 0px; visibility: hidden;"><img src='http://www.mysite.com/phpadsnew/adlog.php?bannerid=4&amp;clientid=8&amp;zoneid=3&amp;source=&amp;block=0&amp;capping=0&amp;cb=47b2a94244b0562b64ae67a2a2b909b6' width='0' height='0' alt='' style='width: 0px; height: 0px;'></div>

The problem is i have some static file where php is not available. So, any suggestions to this? thanks.

Just to add that i notice several big sites such as Jensense are using this method. The javascript code can't be viewed from the source file.


12:57 am on Feb 1, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

Before I started rotating Yahoo/AdSense ads I looked at a variety of different options to implement a rotation solution. CGI was too slow and server intensive, and straight Javascript or CGI+Javascript options appeared to also alter or obstruct the ad code.

I decided in the end to go with straight SSI. Much faster for both the client and the server and it doesn't alter the ad code at all.


6:29 am on Feb 1, 2006 (gmt 0)

10+ Year Member

No idea how to implement an SSI or even find one good SSI for this thing. :(


6:44 am on Feb 2, 2006 (gmt 0)

10+ Year Member

I rotate on the backend, and not in the JavaScript. I think making a separate call to load the ad is too much load.

I created a set of files for my ads along the lines of this:


These files just set size variables and include a centralized file call __ad.php. This file loads up a simple PHP class I created called AdProvider.php. When loaded, the object decides which provider to use (if not explicitly told). For me, I just divide time in larger 1-minute chunks. For now, I divide time in half... 1 minute for AS, 1 minute for YPN, but I could divide time into 10 slices an assign which slices of time each gets. When MSN gets going, I'll just add them to the list of providers.

I might be making this sound more complicated than it is. But really, my rotation comes down to "time_in_minutes() % $slices".

Then in my website PHP pages, I include the _ad_XXXxYYY.php files as needed. Some pages I hard code the provider (ie. Yahoo performs better on those pages, so it gets 100%). Soon, I will be less absolute.



6:47 am on Feb 2, 2006 (gmt 0)

10+ Year Member

Oh yeah... and it supports a common "named" mapping to channel/category... so it plug in the channels if they're configured for the page. :)


7:08 am on Feb 2, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

That's interesting Alex, I also use time based rotation, only using SSI. Here's an example. In this example, it takes the last digit from the seconds in the DATE environmental variable, coming up with a single digit from 0 - 9. Yahoo ads are served when a hit occurs when the digit is 0, 2, 4, 6, and 8. Google ads are served with 1, 3, 5, 7, and 9. It could easily be configured though, to serve ads using a variety of different methods using server time as a seed for rotation.

<!--#if expr="${HTTP_ACCEPT_LANGUAGE} = /en/" -->
<!--#config timefmt=%S -->
<!--#if expr="$DATE_LOCAL = /^[0-5]([0-9])$/" -->
<!--#set var="Time" value="$1" -->
<!--#endif -->
<!--#if expr="($Time = /^[02468]$/) && (${HTTP_ACCEPT_LANGUAGE} = /en-us/)" -->
Show Yahoo ad.
<!--#else -->
Show Google ad.
<!--#endif -->
<!--#else -->
Show alternative ad.
<!--#endif -->


7:17 am on Feb 2, 2006 (gmt 0)

10+ Year Member

Yeah, sounds similar. Although I chose to not divide by seconds and allocate chunks of time by minutes. I figured that using seconds allows for the distribution to be more "random" and unpredictable. A one-minute block adds some stability to the allocation so that it's not just time, but that actual page loads are likely to be more even. :) Hmmm... of course, shorter rotation could expose a user to more ads (AS and YPN) in the span of their visit (if they're a short-time visitor). Maybe I'll try more granular division later.

As for SSI, SSI scares the hell out of me. I work as an application security analyst, and SSI has so many security flaw implications that I'm amazed it's still supported.



7:39 am on Feb 2, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

SSI isn't any more of a security risk than PHP, Perl, or any other server side scripting language.

In fact, ironically enough, I've only had a server hacked once, because of a vulnerability in phpadsnew [trendmicro.com]. Go figure. My mistake for being lazy and using an off the shelf program (so to speak). Won't do that again.


Featured Threads

Hot Threads This Week

Hot Threads This Month