色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

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

<?php 
#########隨機廣告顯示##########  
function myads(){ 
$dir="ads";   #設置存放記錄的目錄  
//$dir="ads";   #設置存放記錄的目錄  
$ads="$dir/ads.txt"; #設置廣告代碼文件 
$log ="$dir/ads.log"; #設置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為顯示加權數(shù),越大顯示次數(shù)越多################ 
################################ 
display=10 

<a href=http://www.mi222.cn>  
<img src="http://www.mi222.cn/logo.gif" alt="米兒網(wǎng)絡歡迎您!"> </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)址導航,網(wǎng)站免費登陸" border="0"></a> 


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

php技術用PHP實現(xiàn)的隨機廣告顯示代碼,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 平顶山市| 柘城县| 安宁市| 喀喇沁旗| 泉州市| 云龙县| 榆中县| 清苑县| 中超| 松桃| 昌邑市| 四川省| 来宾市| 无极县| 宜良县| 德兴市| 蕉岭县| 太湖县| 大石桥市| 潞西市| 米脂县| 徐州市| 临清市| 南丹县| 上蔡县| 苍梧县| 阳东县| 惠安县| 台州市| 邯郸市| 高碑店市| 贵阳市| 贵溪市| 承德市| 新宁县| 巴里| 吴忠市| 繁昌县| 天水市| 寿阳县| 宁津县|