web directoryearn money in seconds   Free file hosting, free video sharing

<<< The Web Hosting >>>


Go Back   Noeman GSM > Webhosting & Website development > Website development > Programming

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-05-2007, 10:08 AM
Spiral's Avatar
CO-Admin
 
Join Date: Sep 2004
Location: Martil
Age: 25
Posts: 15,689
Reputation: 18998
Spiral Mega Super MemberSpiral Mega Super MemberSpiral Mega Super MemberSpiral Mega Super MemberSpiral Mega Super MemberSpiral Mega Super MemberSpiral Mega Super MemberSpiral Mega Super MemberSpiral Mega Super MemberSpiral Mega Super MemberSpiral Mega Super Member
Default Simple Banner Rotator by PHP

we can build a simple banner/image rotator. We will be doing this using flat files (txt files) and a couple of file functions in php.

Here is what the banner txt file should look like, you simply just put one image/link pair per line. The "[$]" seperator is used to split apart the img/link pairs. We use this interesting seperator to ensure it is not going to be contained in the link or image reference.

PHP Code:
google.gif[$]http://www.google.com
mkeefedesign.gif[$]http://www.mkeefedesign.com
scriptplayground.gif[$]http://www.scriptplayground.com 
First off, define the variables for this project

PHP Code:
//
// Customizable Settings for banner script
//
$banner_txt_file 'my_banners.txt'// Our txt file of banner references
$banner_links true// Show banner as just image or with link (href) 
Now lets set up a function to contain all of our banner code and make it easier to call in the future.

PHP Code:
function display_banner() {
    
// use 'global' to reference our preset variables
    
global $banner_txt_file$banner_links
    
    mt_srand
((double)microtime() * 100000);
    
$banners file($banner_txt_file);
    
$count count($banners);
    
$random rand(0$count 1);
    
$banner $banners[$random];
    
$banner_parts explode("[$]"$banner);
    
$banner_img $banner_parts[0];
    
$banner_link $banner_parts[1];

    
$banner_html "<img src=\"" $banner_img "\" />"// build img tag
    
if($banner_links) {
        
$banner_html "<a href=\"" $banner_link "\">" $banner_html "</a>";
    }
    return 
$banner_html// return the html code

Now let's take a moment to explain what is happening in those last few lines. First off we define a few global variables to gain access to them in the function (scope issue).

Then we use mt_srand() to create a random seed, and ultimately allow us to pick a random banner image. Now we begin the file opening process and start reading in our banners and links. We then take these lines of link/img pairs and choose a random one to display. Finally we build our necessary html to display the banner and add the link info if $banner_links is set to true.

Note: Make sure you "chmod" the banner txt file, so it can actually be read.

To display a random banner, you simply place this PHP code somewhere in your file

PHP Code:
print display_banner(); 
Thats it, you now have a working php banner script.
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 10-10-2007, 02:23 AM
Junior Member
 
Join Date: Oct 2007
Age: 26
Posts: 6
Reputation: 10
googleccd is on a distinguished road
Smile nice

this is so cooooold tanks man.
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 01:18 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
Copyright © 2004-2008 Noeman . All rights reserved
Hotel Marseille | Remortgaging | Mortgage | Credit Cards | Debt Management

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111