国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

隨機廣告顯示(PHP函數)

瀏覽:3日期:2023-12-21 18:08:29
<?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 >;;<img src="http://china.chance2mail.com/images/banner/c_banner.gif" alt="Chance2mail,好禮物送給您!"> </a> ################################ display=10 <a target=_blank> <img src="http://www.free868.com/~xinyi/ads/8848.gif" width="468" height="60" alt="歡迎到My8848網站購物" border="0"></a> 調用<?php myads();?>即可
標簽: PHP
主站蜘蛛池模板: 绵阳市| 聂荣县| 四会市| 宁安市| 手游| 元阳县| 武强县| 武定县| 海城市| 辽宁省| 海口市| 桐梓县| 谷城县| 太和县| 晋州市| 岐山县| 新疆| 黎城县| 哈尔滨市| 龙门县| 丹棱县| 福建省| 图木舒克市| 莲花县| 宁夏| 信丰县| 丰镇市| 乐东| 石阡县| 昆明市| 孟村| 林西县| 扶绥县| 弥勒县| 团风县| 高清| 平遥县| 炉霍县| 庆城县| 阿勒泰市| 乌鲁木齐县|