找回密码
 注册账户
查看: 5537|回复: 6

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

[复制链接]
admin 发表于 2008-1-3 03:28:07 | 显示全部楼层 |阅读模式
演示
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[3]}'\" title='{$e[0]}' width='180' style='cursor:pointer'>
<a href='{$e[3]}' style='font:13px Arial; font-weight:bold; color: #0000ff'>{$e[0]}</a><br>
<span style='font:12px Arial; color: #333333'>{$e[1]}</span><br>
<a href='{$e[3]}' style='font:10px Arial; color: #009900'><i>{$e[2]}</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 | 显示全部楼层
您需要登录后才可以回帖 登录 | 注册账户

本版积分规则

存档|黑屋|手机|网络实验室 本站服务器由美国合租以及IDCLayer国际数据提供!!!

GMT+8, 2026-6-5 00:21 , Processed in 0.019841 second(s), 8 queries , Gzip On, Redis On.

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表