JS调用法
JS代码,先用记事本,输入 (下面红的改成你自己的)
<!--
a = 4 // a=banner数目
var slump = Math.random();
var talet = Math.round(slump * (a-1))+1;
function create() {
this.width = ''
this.height = ''
this.src = ''
this.href = ''
this.border = ''
this.alt = ''
this.under = ''
}
b = new Array()
for(var i=1; i<=a; i++) { b[i] = new create() }
b[1].src = "images/banner1.gif"
b[1].href = "http://vyoo.net"
b[1].width = "468"
b[1].height = "60"
b[1].border = "0"
b[1].alt = "网游中心"
b[1].under = '网游中心'
b[2].src = "images/banner2.gif"
b[2].href = "http://vyoo.net"
b[2].width = "468"
b[2].height = "60"
b[2].border = "0"
b[2].alt = "####"
b[2].under = '####'
b[3].src = "images/banner3.gif"
b[3].href = "http://vyoo.net"
b[3].width = "468"
b[3].height = "60"
b[3].border = "0"
b[3].alt = "#####"
b[3].under = '#####'
b[4].src = "images/banner4.gif"
b[4].href = "http://vyoo.net"
b[4].width = "468"
b[4].height = "60"
b[4].border = "1"
b[4].alt = "#######"
b[4].under = '#######' //依此类推
var visa = "";
visa += '<a href="'+b[talet].href+'">'
visa += '<img src="'+b[talet].src+'" height='+b[talet].height
visa += ' width='+b[talet].width+' border='+b[talet].border+' alt='+b[talet].alt+'>';
visa += '</a>'
function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
//-->
将改好的文件另存为****.js文件(****为文件名),并在需要放置广告的页面中引用。
引用*.js文件的方法是:在页面的原文件中的<head>与</head>之间插入代码
<script language="javascript" src="****.js"></script> 记得将红字改成你的文件名
在页面需要放置广告banner的地方加上下面的代码:
<script language="JavaScript"><!--
document.write(visa);
//-->
</script>
PHP函数法
<?php
#########随机广告显示##########
function myads(){
$dir="ads"; #设置存放记录的目录
//$dir="ads"; #设置存放记录的目录
$ads="$dir/ads.txt"; #设置广告代码文件
$log ="$dir/ads.log"; #设置ip记录文件
$ads_lines=file($ads);
$lines=count($ads_lines);#文件总行数
####读出广告总数$ads_count和显示次数到数组$display_array########
$ads_count=0;
$display_count=0;
for ($i=0;$i<$lines;$i++){
if((!strcmp(substr($ads_lines[$i],0,7),"display"))){
$ads_count+=1;
$display_array[$ads_count]=substr($ads_lines[$i],8);
$display_count+=$display_array[$ads_count];
}
}
####决定随机显示序号$display_rand#####
srand((double)microtime()*1000000);
$display_rand = rand(1,$display_count);
###决定广告序号$ads_num######
$pricount=0;
$ads_num=1;
for($i=1; $i<=$ads_count; $i++) {
$pricount += $display_array[$i];
if ($display_rand<=$pricount) {$ads_num=$i;break;}
}
#####播放广告代码#########
$num=0;
$flag=0;
for($i=0;$i<$lines;$i++){
if((!strcmp(substr($ads_lines[$i],0,7),"display"))){$num++;}
if(($num==$ads_num)and($flag==0)){$flag=1;continue;}
if(($flag==1)and strcmp($ads_lines[$i][0],"#")){echo $ads_lines[$i];continue;}
if(($flag==1)and(!(strcmp($ads_lines[$i][0],"#")))){break;}
}
####纪录广告显示次数#########
$fp=fopen($log,"a");
fputs($fp,date( "Y-m-d H:i:s " ).getenv("REMOTE_ADDR")."==>".$ads_num."\n");
fclose($fp);
}
?>
广告代码文件ads.txt
########每个广告代码之间用'#'隔开,display为显示加权数,越大显示次数越多################
################################
display=10
<a href="http://china.chance2mail.com/cgi-bin/regstep1.cgi?myid=CC00099599">
<img src="/ShowImg.asp?p=/2006-4-18/32665c_banner.gif" alt="Chance2mail,好礼物送给您!"> </a>
################################
display=10
<a href="http://www.my8848.net/agtunion/agtredirect.asp?act=homepage&agtid=2986" target=_blank>
<img src="/ShowImg.asp?p=/2006-4-18/65510adsa8848.gif" width="468" height="60" alt="欢迎到My8848网站购物" border="0"></a>
调用<?php myads();?>即可

Tags: 





