Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   PHP (http://www.programmingforums.org/forum29.html)
-   -   Adrotator (http://www.programmingforums.org/showthread.php?t=15089)

kinuthia Jan 30th, 2008 11:49 AM

Adrotator
 
Hello all,
Can someone tell me how to use an adrotator in php. In asp you can use <asp:adrotator:............................. />

I need to do the same in php.
Please help.
Thanks all.

Sane Jan 30th, 2008 11:56 AM

Re: Adrotator
 
You could make one very easily yourself. In fact, it's already been done. http://www.phpbuddy.com/article.php?id=4

If it doesn't fit your needs, just modify/extend it. Or search "php adrotater" on Google.

kinuthia Jan 30th, 2008 6:13 PM

Re: Adrotator
 
Thanks alot Sane.

I have tried but for some reasons its not working.

Sane Jan 31st, 2008 12:29 PM

Re: Adrotator
 
Could you post the code? What exactly is the problem?

kinuthia Feb 1st, 2008 6:12 AM

Re: Adrotator
 
Thanks Sane. I think the code is okey. I tested it in a different page and it works okey. The thing is i'm trying to use it in a templated website and that is where its not working. I think i have to create another function to handle this. I honestly don't know how to do it but im still trying to look for ways. Im not an expert in PHP but just started to learn it a month ago.

Sane Feb 1st, 2008 8:10 AM

Re: Adrotator
 
You could wrap the code I linked to, into a function, and save it as a separate PHP script.

adrotater.php

:

  1. <?php
  2.  
  3. function adrotater($filename) {
  4.     $fcontents = join ('', file ($filename));
  5.     $s_con = split("~",$fcontents);
  6.  
  7.     $banner_no = rand(0,(count($s_con)-1));
  8.     echo $s_con[$banner_no];
  9. }
  10.  
  11. ?>


Place the above file, adrotater.php, in the same directory as your other scripts. This would allow you to use the function, in your main PHP file, like so:

index.php

:

  1. <?php
  2.  
  3. // Include the separate PHP script
  4. include('adrotater.php');
  5.  
  6. //
  7. // Blah blah blah, some code here
  8. //
  9.  
  10. // Display a random advertisement from banner_ads.txt
  11. adrotater('banner_ads.txt');
  12.  
  13. //
  14. // More code here
  15. //
  16.  
  17. ?>


Make sure to include the adrotater.php file in every file you want to use the adrotater function.

Then the argument passed to it, 'banner_ads.txt', is the text file with the advertisements inside.

Ooble Feb 3rd, 2008 2:16 PM

Re: Adrotator
 
Does PHP's rand function return numbers uniformly? If it doesn't, it's probably a poor choice for this sort of thing.

As an aside, it's spelt "rotator." No offence, Sane. ;)

Sane Feb 3rd, 2008 6:17 PM

Re: Adrotator
 
It would return it uniformly enough. Anything random would be good enough for an adrotator.

And wow, I had no clue I was spelling that incorrectly. Thanks for the correction. :$

kinuthia Feb 3rd, 2008 6:21 PM

Re: Adrotator
 
Ooble
Any alternatives.

kinuthia Feb 3rd, 2008 6:24 PM

Re: Adrotator
 
Sane

Im still trying to figure this out. I have to incorperate the function in other functions list where it will be called from.


All times are GMT -5. The time now is 2:17 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC