I wanna have a banner on my site that will direct to different advertiser each time a person clicks on it. How to do that. Example, i have 5 links, that i want rotate under that banner
This page explains some PHP with very similar logic - http://www.monetizationhub.com/displaying-random-ads/
Take a look at my article: http://kzzen.com/2008/10/php-random-content-rotater/ it might be able to help you
Try this, its simple: <?php //Add as many links you want $mylink[1] = '<a href="http://www.aioshared.com">Free Rapidshare Search Engine</a>'; $mylink[2] = '<a href="http://www.hotmail.com">Free 5gb Mailbox</a>'; $mylink[3] = '<a href="http://www.mozilla.org">Fastest and Secure Web Browser</a>'; //.... //.... //Change 3 to as many links you have added above $id = rand(1,3); echo $mylink[$id]; ?> PHP: Hope its what you are looking for...
for better solution : <?php //Add as many links you want $mylink[1] = '<a href="http://www.pegor.com">Free PHP Tutorials</a>'; $mylink[2] = '<a href="http://www.lifestinks.info">Fast Facebook Proxy</a>'; $mylink[3] = '<a href="http://www.mozilla.org">Fastest and Secure Web Browser</a>'; //$mylink[4] = ..... //$mylink[5] = .... // this will count your links itself and select a random one $id = rand(1,count($mylink)); // this will display the random link echo $mylink[$id]; ?> PHP:
so i just copy and paste it in my html file? and where the banner goes? I wanna have same banner but each time you someone clicks on it it goes to one of the URLs
@Nik555: You need to use php page, not html page. i.e. page with extension .php See the bold part in the below code...that's how you use banners in link. $mylink[1] = '<a href="http://www.pegor.com"> [B]<img src="images/banner.jpg" width="468" height="60" alt="some_tex_there">[/B]</a>'; Code (markup): Modify code of nastynappy to see image banners in all links using this method.
so i make php file. then i put a banner on my html page, and under a banner i put a link to that php file , correct?
No, just rename your html page with php. say index.html will be index.php then in the body where you want to put the banner modify the code as <body> <div id=banner> <?php //Add as many links you want $mylink[1] = '<a href="http://www.pegor.com"> <img src="images/banner1.jpg" width="468" height="60" alt="some_tex_here"> </a>'; $mylink[2] = '<a href="http://www.lifestinks.info"> <img src="images/banner2.jpg" width="468" height="60" alt="some_tex_here"></a>'; $mylink[3] = '<a href="http://www.mozilla.org"><img src="images/banner3.jpg" width="468" height="60" alt="some_tex_here"></a>'; //$mylink[4] = ..... //$mylink[5] = .... // this will count your links itself and select a random one $id = rand(1,count($mylink)); // this will display the random link echo $mylink[$id]; ?> </div> Code (markup): don't forget to keep the php codes inside <? and ?> Hope it's perfect to understand now.
actually it works now, but it works like that: it goes 5 times to 1 link and then 5 times to another, is it possible for it to work like 1link,2nd link,3rd link and then all over, instead of just taking random link
keep it simple guys <? $links="http://google.com,http://yahoo.com,http://msn.com"; $linkx=explode(",",$links); shuffle($linkx); echo"$linkx[0]"; ?> Code (markup):
If permissions are setup on your server in a way that PHP can read/write files safely, this way will make it easier to change the URLs later. Create a file named "items.txt" and in that file put each of the items to be rotated on their own line. For your 5 links the file might look like <a href="http://www.one.com/?ref=me">One</a> <a href="http://www.two.com/?ref=me">two</a> <a href="http://www.three.com/?ref=me">three</a> <a href="http://www.four.com/?ref=me">four</a> <a href="http://www.five.com/?ref=me">five</a> Code (markup): Then in your page, assuming it's a PHP page or HTML is setup to be parsed as PHP, you place this anywhere you want the rotation to show. <?php $items_file = 'items.txt'; $urls = file($items_file); array_push($urls, array_shift($urls)); echo trim($urls[0]); file_put_contents($items_file, implode('', $urls)); ?> Code (markup): That way you can use the same PHP everywhere you want it to happen, and changes made to "items.txt" are reflected in all of those places. That, and a plain text file is usually easier to deal with.
Nah, the contents of "items.txt" can be anything you want it to be, just remember that each line is a new item. Also remember, if you put an empty newline at the end of the file you will end up with an empty item in the rotation.
You put anything you want rotated on its' own line. If you have something like this in your webpages now <a href="http://domai.com/"><img src="banner.png" alt="visit *"/></a> Code (markup): Then you will replace that with the PHP I posted earlier, and your "items.txt" might look like this to alternate between two banners. <a href="http://domai.com/"><img src="banner.png" alt="visit *"/></a> <a href="http://example.com/"><img src="banner-2.png" alt="visit *"/></a> Code (markup):