NamePros.Com (http://www.namepros.com/)
-   CODE (http://www.namepros.com/code/)
-   -   Random add Script (http://www.namepros.com/code/183969-random-add-script.html)

Xyzer 04-05-2006 01:50 AM

Random add Script
 
Hi,

If you want a copy its nice and easy in php, just put where you want the ads to appear:
Code:
<?php srand( microtime() * 1000000); $advertise = rand(1,3); //After the rand decided how many youve got and the first and last number e.g got 3, 1,3 switch($advertise) //you can add more just use the same format { case 1 : $banner="site 1 image url"; $url="site one address"; break; case 2 : $banner="site 2 image url"; $url="site two address"; break; case 3 : $banner="site 3 image url"; $url="site 3 address"; break; } $display = "<a href=\"$url\" target=\"_blank\"> "; $display.= "<img src=\"$banner\" "; $display.= "width=\"468\" height=\"60\" border=\"0\" >"; $display.="</a>"; echo($display); ?>


Thanks and enjoy.

p.s (I Like rep :hehe:)

cvxdes 04-05-2006 05:49 PM

And if you want FlatDB, I just wrote this.

In your DB file, put:
Code:
http://www.hi.com||http://www.hi.com/hi.png http://www.hi2.com||http://www.hi2.com/hi.png


The php:
PHP Code:
<?
funtion ad_template
($url, $img){
    
$ad = "<a href='".$url."'><img src='".$img."' alt=''/>";
    return
$ad;
}
$i = 0;
$lines = file('addb.txt');
foreach(
$lines as $line){
    
$i++;
    
$data = explode("||", $line);
    
$return[$i] = ad_template($data[0], $data[1]);
}
$number = rand(0,$i);
echo
$return[$number];
?>

Borghunter 04-15-2006 01:31 PM

That's a pretty useful script, I'll use it everywhere! :)

Added Random Ad Sizes.
PHP Code:
<?php
srand
( microtime() * 1000000);
$advertise = rand(1,3);
//After the rand decided how many youve got and the first and last number e.g got 3, 1,3
switch($advertise)
//you can add more just use the same format
{
case
1 : $banner="site 1 image url"; $url="site one address"; $imgwidth="88"; $imgheight="31"; break;
case
2 : $banner="site 2 image url"; $url="site two address"; $imgwidth="50"; $imgheight="50"; break;
case
3 : $banner="site 3 image url"; $url="site 3 address"; $imgwidth="468"; $imgheight="60"; break;
}
$display = "<a href=\"$url\" target=\"_blank\"> ";
$display.= "<img src=\"$banner\"  ";
$display.= "width=\"$imgwidth\" height=\"$imgheight\" border=\"0\" >";
$display.="</a>";
echo(
$display);
?>

Xyzer 04-15-2006 10:46 PM

I could have added the sizes, ill do that on the next version that comes, out, cvxdes, i dont see what you are trying to do, break into my thread, mine is just a flat db, no mysql or anything involved.

weblord 04-15-2006 10:55 PM

nice script, rep is coming your way.

Xyzer 04-15-2006 11:11 PM

Oh, thanks! Its a script i needed to do something then when i learnt php, everyone is liking it.

Phoenix 06-21-2006 01:18 PM

Very nice, was looking for something like this a while ago :D..!

kleszcz 08-24-2006 01:20 PM

Simply basic but applicable to any object with modifications. Thanks. ;)


All times are GMT -7. The time now is 05:59 AM.
Site Sponsors
Advertise your business at NamePros

Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0