TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

April 18, 2024, 05:14:47 PM

Login with username, password and session length
Members
  • Total Members: 3,885
  • Latest: Growner
Stats
  • Total Posts: 195,164
  • Total Topics: 21,219
  • Online today: 203
  • Online ever: 3,540 (September 03, 2022, 01:38:54 AM)
Users Online
  • Users: 1
  • Guests: 174
  • Total: 175
  • @rjen

Multiple banner ad rotator?

Started by Adamzon, January 22, 2007, 12:44:34 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Adamzon

Hi!
Im need a script to rotate up to 10 lines/banners on my site www.glidarhoj.se
I have tried some diffrent scripts with include but i cant get it to work  :idiot2:

Do u have any idea?
www.glidarhoj.se



Ianedres

Something I've used before...


<?php
$filename 
"path_to\oneliners.txt";
$handle fopen($filename"rb");
$contents fread($handlefilesize($filename));
fclose($handle);

$ads explode("\n"$contents);
$totalads count($ads)-1;
$i rand(0$totalads);

echo 
$ads[$i];
?>


In the filename 'oneliners.txt', just make sure you point the script to the proper path for it. Each line is read by the script on a random basis. You can even include valid HTML code within each line.

JPDeni

Create a php block.

Put the following code in it, filling in the urls to your banners and links as needed, one per line:


$banners = array (
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>',
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>',
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>',
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>',
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>',
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>',
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>',
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>',
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>',
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>',
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>'
);

shuffle($banners);

echo $banners[0];


It's easy to edit, you don't have to have any external files, and you can have as many or as few banners as you want.

Adamzon

Great! But i need a multiple-line.

10 banners would be great

/Adam

JPDeni

QuoteBut i need a multiple-line

Can you give me an example of what you need?

TolerancE

FINALLY! I've been looking for this for what seems like forever.

Adamzon

Look @ www.lidkopingsnytt.nu
in the right column (ads)
He has many diffrent ads, and they change places with every page open.

I have tried to inlude som diffrent php random banner generators but i cant get it to work :(
(in the big, all scripts that www.hotscripts.com has to offer in the randomize banner scripts)


/adam

JPDeni

Oh. You want multiple banners. Well that's easy enough.

Keep the same code as I gave you above. Instead of


echo $banners[0];


use


$number_of_banners = 4; // put the number of banners you want to display here;

for ($i = 0; $i < $number_of_banners; ++$i)
  echo $banners[$i] , '<br />';

Adamzon

OMG! U are wonderful!!! THANX!!

Is there anyway to specifie the width of the banners?

/Adam

JPDeni

Just put the height and width in the img tags like you would put it in any other html img tags. There's nothing magical about them. :)

You're welcome. ;D