-
Random Affiliate
is there a very simple and small script to randomly select an affiliate banner and rotate it everytime the page is loaded i found a few but they have like 50 lines of codes,i use to use one a few yrs ago that was just 5 lines and was a simple <ahref="link"><img src='imgurl"> with 3 lines ontop and 2 under.:o
-
Rotating a banner each time the page loads is kinda bad. Make sure the filesize is small enough... or it will really slow down the users on slower connections.
You might want to use cookies/sessions to keep track of the one that user got and keep it the same through a whole session on your site.
(or maybe you need them to see all the choices as they browse around)
Could you use php? Not that hard in that, just don't know the code in JS.
PHP Code:
top of your page:
<?php
$array[0] = "insert tags here";
$array[1] = "more here";
//add entries as you please
$thing = $array[rand(0,1)]; //note that the 1 is to be replaced with the highest number above in the array list.
?>
then in your content, put this:
<?php echo $thing; ?>
You could code something similar in javascript, but I don't know the codes right now... you could look them up. Use arrays (note the $ is only used in php... no need for it in javascript), use a random number, then just change somethign on the page to the random number entry of the array. That's it.
-
well yeah i think i could use php just that i know more about JS,in this part here where would i put the image url and where would i put the linkmsomething like :
<?php
$array[0] = "imageurl.gif,http://linktogoto.com";
$array[1] = "more here";
And that session part sounds really interesting,how would i insert it into this script? i heard of them before and seen some use it but never though of addin it to the ratating banners,thxs for the help :p
Mav
-
At the very top of your page, before anything else (including whitespace):
Code:
<?php
error_reporting(E_ALL);
session_start();
$image = array(
array(
'image' => 'imageurl.gif',
'link' => 'http://linktogoto.com'
),
array(
'image' => 'imageurl.png',
'link' => 'http://anotherlinktogoto.com'
),
array(
'image' => 'imageurl.jpg',
'link' => 'http://yetanotherlinktogoto.com'
)
);
if(!isset($_SESSION['curimg']))
$_SESSION['curimg'] = rand(0, count($image) - 1);
$image = $image[$_SESSION['curimg']];
$image = '<a href="' . $image['link'] . '"><img src="' . $image['image'] . '"></a>';
?>
Where you want the image to appear:
Code:
<?php echo($image); ?>
That will keep the banner the same for each user who visits your site, as per djr33's idea.
-
I believe sessions are only server side, or at least limited using javascript. (you could use a cookie instead, or something, I guess)
php is a good language to learn.
(And, for me, javascript is a good language to learn)
so.. I do understand where you're coming from.
-
that seems like a great script idea to get the images catched in the cache,i tried Twey's script and it displays the image but only the first one then i reloaded several times and it doesn't make it rotate?
-
twey's script DOESN'T rotate based on refreshing. That's the point of sessions.
It will keep the banner the same, so it doesn't need to reload each time and slow down transfers of the pages.
It will be random at the start of each visit, then stay the same throughout the visit.
Taking that out would be easy, but it's certainly worth considering... will be a LOT nicer for dialup users.
-
oh ok but it will change once you close to browse and revist?then thats fine :) another thing,is it possible to open the link in a new windows maybe something like :
$image = array(
array(
'image' => 'imageurl.gif',
'link' => 'http://linktogoto.com' target='_blank' ?
-
Code:
$image = '<a href="' . $image['link'] . '" target="_blank"><img src="' . $image['image'] . '"></a>';
-
Hey,
I'v been using this script for a while and it works awesome but sometimes this error comes up:
Notice: Undefined index: curing in /home/.foobar/dexter/ads/rightad.php on line 195
Line 195 is $image = $image[$_SESSION['curimg']];
Or Notice: Undefined offset: 65 in /home/.foobar/dexter/ads/rightad.php on line 195
Does anyone know why? Thanks