成人在线亚洲_国产日韩视频一区二区三区_久久久国产精品_99国内精品久久久久久久

您的位置:首頁技術(shù)文章
文章詳情頁

隨機(jī)廣告顯示(PHP函數(shù))

瀏覽:2日期:2023-12-21 18:08:29
<?php #########隨機(jī)廣告顯示##########;;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]; } } ####決定隨機(jī)顯示序號(hào)$display_rand##### srand((double)microtime()*1000000); $display_rand = rand(1,$display_count); ###決定廣告序號(hào)$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;} } ####紀(jì)錄廣告顯示次數(shù)######### $fp=fopen($log,"a"); fputs($fp,date( "Y-m-d H:i:s " ).getenv("REMOTE_ADDR")."==>".$ads_num."n"); fclose($fp); } ?> 廣告代碼文件ads.txt ########每個(gè)廣告代碼之間用'#'隔開,display為顯示加權(quán)數(shù),越大顯示次數(shù)越多################ ################################ 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網(wǎng)站購物" border="0"></a> 調(diào)用<?php myads();?>即可
標(biāo)簽: PHP