Dynadot โ€” .com Registration $8.99

Ad Randomizer?

Spaceship Spaceship
Watch
Impact
34
Im looking for an ad randomizer, all the ones ive found on the internet are just for images/links but i want it for javascript ads eg, google adsense, theres 2 ads I want too rotate/randomize

anyone know a good script or can make one?


thanks
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
.US domains.US domains
Are we able to get one that can randomize the code a percentage of the time (like 50/50 if it were two ads, for example)?
 
0
•••
try this opensource called openx
http://www.openx.org/
it also accommodates flash aside from javascript ads
 
0
•••
Or one that just randomly shows 1 of 2 ad codes, in fine with either
 
0
•••
if its 1 of two codes, then you can code it easily yourself.

PHP:
$rand = rand(0,1);
switch($rand) {
case 0:
echo "HTMLCODEFOR1";
break;
case 1:
echo "HTMLCODEFOR2";
break;
}
 
0
•••
Can you please explain exactly where in the htm page that code goes and also where the adsense and ypn code is inserted?

Thanks.

nasaboy007 said:
if its 1 of two codes, then you can code it easily yourself.

PHP:
$rand = rand(0,1);
switch($rand) {
case 0:
echo "HTMLCODEFOR1";
break;
case 1:
echo "HTMLCODEFOR2";
break;
}
 
0
•••
I'd assume the code would go whereever you want the ad. So you could put it in a .php file and just include() it.
 
0
•••
This is assuming your host has PHP installed.

You'd need to rename the file to a .php extension, and then put in this code wherever you want the ads to display:

PHP:
<?php
$rand = rand(0,1);
switch($rand) {
case 0:
echo 'HTMLCODEFOR1';
break;
case 1:
echo 'HTMLCODEFOR2';
break;
} 
?>

Just keep in mind, if the text you put in HTMLCODEGOESHERE contains any SINGLE quotes ('), then you must escape them by adding a \

here's an example:
PHP:
echo '<a href="javascript:go.history(\'-1\')">back</a>';
notice how i have the \ before each '.
 
0
•••
Is the code below correct?

Thanks.



This is assuming your host has PHP installed.

You'd need to rename the file to a .php extension, and then put in this code wherever you want the ads to display:

PHP:
<?php
$rand = rand(0,1);
switch($rand) {
case 0:
echo '<SCRIPT TYPE="text/javascript"><!--
google_ad_client = "pub-0123456789";
google_ad_width = 120;
google_ad_height = 600;
google_ad_format = "120x600_as";
google_ad_channel ="";
google_color_border = "8FBEE8";
google_color_bg = "8FBEE8";
google_color_link = "0000ff";
google_color_url = "000000";
google_color_text = "000000";
//--></SCRIPT>
<SCRIPT TYPE="text/javascript" SRC="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</SCRIPT>';
break;
case 1:
echo '<script language="JavaScript" type="text/javascript">
<!--
ctxt_ad_partner = "0123456789";
ctxt_ad_section = "12345";
ctxt_ad_bg = "";
ctxt_ad_width = 120;
ctxt_ad_height = 600;
ctxt_ad_bc = "FFFFFF";
ctxt_ad_cc = "FFFFFF";
ctxt_ad_lc = "0000FF";
ctxt_ad_tc = "000000";
ctxt_ad_uc = "999999";
// -->
</script>
<script language="JavaScript" src="http://ypn-js.overture.com/partner/js/ypn.js">
</script>';
break;
} 
?>

Just keep in mind, if the text you put in HTMLCODEGOESHERE contains any SINGLE quotes ('), then you must escape them by adding a \

here's an example:
PHP:
echo '<a href="javascript:go.history(\'-1\')">back</a>';
notice how i have the \ before each '.
 
0
•••
PHP for me is bloody difficult, the implementation of it is pretty straight-forward and I can do that and make minor edits to PHP coding. I can't however, code scripts from scratch and it gets really frustrating when I have a ton of errors.
 
0
•••
trader:
yes that looks fine.

psychotic:
tons of errors are the easiest to fix with php since it tells you exactly whats wrong on exactly which line. you just gotta get good and understaind what it complains about. for example, if it says unexpected T_END or something, you probably forgot a } or if it says blah is not valid for blah then you probably forgot a semicolon on the line before. it takes some practice, but pretty straightforward.
 
0
•••
nasaboy007 said:
trader:
yes that looks fine.

It only took 2 minutes to implement it on a site and it works perfectly B-)

Thanks for you great code and help.

The only issue I have is I prefer not to change all my index.html pages to php, is there a way to do this without using php?
 
0
•••
The script doesn't work for me, most other scripts didn't. I think it may be because of the CMS I use, but I'm not entirely sure.
 
0
•••
sometimes this works, sometimes it doesnt, but it's worth a shot:

go to your .htaccess file in your root of the site, and add this:
Code:
RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html

then you shouldn't need to rename all your files to .php and .html files will parse php.


glad to help.


psychotic:
are you sure your host has PHP installed? what if you just make a file called phpinfo.php, and put this in it:
PHP:
<?php
phpinfo();
?>
and uploaded it, and viewed it. does it work?
 
0
•••
Trust me, PHP is installed otherwise MODx wouldn't work at all lol. It uses PHP and MySQL. I'll actually try that .htaccess thing, HTACCESS is such a useful thing (something I would probably take the time to learn actually) because MODx codes pages in pure HTML and it sometimes comes up with PHP parsing errors.

I also know PHP works because I have Wordpress on the same server for my personal blog/portfolio.
 
Last edited:
0
•••
Thanks for the help guys, I've found a solution :)
 
0
•••
majinbuu1023 said:
Thanks for the help guys, I've found a solution :)

I might try that .htaccess solution though, just to see if it works lol.
 
0
•••
lol glad to be of assistance

psychotic:
that's just weird X_X
 
0
•••
nasaboy007 said:
lol glad to be of assistance

psychotic:
that's just weird X_X

What is? I do a lot of weird stuff, lmao.
 
0
•••
its weird how it refuses to work for simple custom scripts even though you have all those php powered scripts running fine.
 
0
•••
Dynadot โ€” .com Registration $8.99Dynadot โ€” .com Registration $8.99
Unstoppable Domains
Domain Recover
DomainEasy โ€” Live Options
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back