最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

用PHP實現(xiàn)的隨機廣告顯示代碼

 更新時間:2007年06月14日 00:00:00   作者:  
<?php 
#########隨機廣告顯示##########  
function myads(){ 
$dir="ads";   #設(shè)置存放記錄的目錄  
//$dir="ads";   #設(shè)置存放記錄的目錄  
$ads="$dir/ads.txt"; #設(shè)置廣告代碼文件 
$log ="$dir/ads.log"; #設(shè)置ip記錄文件 

$ads_lines=file($ads); 
$lines=count($ads_lines);#文件總行數(shù) 

####讀出廣告總數(shù)$ads_count和顯示次數(shù)到數(shù)組$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;} 

####紀錄廣告顯示次數(shù)######### 
$fp=fopen($log,"a"); 
fputs($fp,date( "Y-m-d H:i:s " ).getenv("REMOTE_ADDR")."==>".$ads_num."\n"); 
fclose($fp); 

?> 

廣告代碼文件ads.txt 

########每個廣告代碼之間用'#'隔開,display為顯示加權(quán)數(shù),越大顯示次數(shù)越多################ 
################################ 
display=10 

<a href=http://www.mi222.cn>  
<img src="http://www.mi222.cn/logo.gif" alt="米兒網(wǎng)絡(luò)歡迎您!"> </a> 
################################ 
display=10 

<a href=http://www.mi222.cn/dh target=_blank> 
<img src="http://www.mi222.cn/dh/QQCF_Pic/logo.gif" width="120" height="60" alt="米兒網(wǎng)址導(dǎo)航,網(wǎng)站免費登陸" border="0"></a> 


調(diào)用<?php myads();?>即可

相關(guān)文章

最新評論

祁东县| 财经| 仁怀市| 尼木县| 溧水县| 皋兰县| 开原市| 即墨市| 清远市| 屏东县| 东光县| 正蓝旗| 安阳县| 南召县| 万山特区| 景东| 通河县| 永嘉县| 鹰潭市| 建阳市| 临颍县| 古田县| 嵊泗县| 盱眙县| 海淀区| 囊谦县| 山阴县| 泸水县| 德江县| 怀集县| 米易县| 丽水市| 桃园县| 美姑县| 萍乡市| 贡山| 平远县| 二连浩特市| 宣武区| 万州区| 张家港市|