admin 发表于 2008-1-3 03:28:07

仿Adsense样式 刷新换广告的代码

演示
http://phpscriptexpert.com/demo/simple_ad_rotator/example.php
刷新会看到不同的广告 按F5就可以刷新

To define a new ad just insert a new line like this:
$ad[] = array("Ad title ", "Ad description ", "Display URL", "URL");

To display the ads include the file "ad_rotator.php" and after that call the functions show_ads().
Example:

<?php

include ("/path/to/ad_rotator.php");

show_ads(3); // this will display 3 ads

show_ads(1); // this will display 1 ad

?>

<?php
/*************************************************
* Simple AD Rotator
*
* Version: 1.0
* Date: 2007-08-30
*
* Include this php file into your site and call the
* show_ads() function with a number of ads
* you want to display.
*
* See example.php
*
****************************************************/

//USAGE $ad[] = array("Title", "Description", "display url", "url");

$ad[] = array("Title 0", "Some description for Ad 0", "www.google.com", "http://www.google.com");
$ad[] = array("Title 1", "Some description for Ad 1", "www.google.com", "http://www.google.com");
$ad[] = array("Title 2", "Some description for Ad 2", "www.google.com", "http://www.google.com");
$ad[] = array("Title 3", "Some description for Ad 3", "www.google.com", "http://www.google.com");
$ad[] = array("Title 4", "Some description for Ad 4", "www.google.com", "http://www.google.com");
$ad[] = array("Title 5", "Some description for Ad 5", "www.google.com", "http://www.google.com");
$ad[] = array("Title 6", "Some description for Ad 6", "www.google.com", "http://www.google.com");
$ad[] = array("Title 7", "Some description for Ad 7", "www.google.com", "http://www.google.com");
$ad[] = array("Title 8", "Some description for Ad 8", "www.google.com", "http://www.google.com");
$ad[] = array("Title 9", "Some description for Ad 9", "www.google.com", "http://www.google.com");

// Function to display random ads from the list
function show_ads($number_of_ads=1){
    // Loading the ads list
    global $ad;
   
    // maximul number of ads = number of ads
    if($number_of_ads > count($ad)){
      $number_of_ads = count($ad);
    }
   
    // Initialize the random generator
    list($usec, $sec) = explode(' ', microtime());
    srand((float) $sec + ((float) $usec * 100000));
   
    // select random ads
    $rand_keys = array_rand($ad, $number_of_ads);
   
    // creade ads
    $show_ads = "<table><tr>";
    for($i=0; $i<$number_of_ads; $i++){
      $e = $ad[$rand_keys[$i]];
      $show_ads .= "
<td onClick=\"document.location='{$e}'\" title='{$e}' width='180' style='cursor:pointer'>
<a href='{$e}' style='font:13px Arial; font-weight:bold; color: #0000ff'>{$e}</a><br>
<span style='font:12px Arial; color: #333333'>{$e}</span><br>
<a href='{$e}' style='font:10px Arial; color: #009900'><i>{$e}</i></a>
</td>
";
    }
    $show_ads .= "</tr></table>";
   
    echo $show_ads;
}
   
?>

lzmhit 发表于 2008-1-8 00:50:22

测试了一下,不错。

kshongmo 发表于 2008-1-15 13:30:25

支持老大!!

礷天 发表于 2008-1-17 12:13:49

功能不错的。。支持。

xiin 发表于 2008-1-17 15:49:08

支持下..

poeeop 发表于 2008-3-28 09:44:19

支持下。。。。。。。。

e文=8懂 发表于 2008-8-28 08:00:00

页: [1]
查看完整版本: 仿Adsense样式 刷新换广告的代码