亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

用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)文章

最新評論