#########隨機廣告顯示##########
function myads(){
$dir="ads"; #設置存放記錄的目錄
//$dir="ads"; #設置存放記錄的目錄
$ads="$dir/ads.txt"; #設置廣告代碼文件
$log ="$dir/ads.log"; #設 " /> 欧美卡一卡二,欧美hdxxxx,久久精品国产亚洲aⅴ

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

隨機廣告顯示(PHP函數)

<?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 href="http://china.chance2mail.com/cgi-bin/regstep1.cgi?myid=CC00099599">  
<img src="http://china.chance2mail.com/images/banner/c_banner.gif" alt="Chance2mail,好禮物送給您!"> </a>
################################
display=10

<a href="http://www.my8848.NET/agtunion/agtredirect.ASP?act=homepage&agtid=2986" target=_blank>
<img src="http://www.free868.com/~xinyi/ads/8848.gif" width="468" height="60" alt="歡迎到My8848網站購物" border="0"></a>


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

php技術隨機廣告顯示(PHP函數),轉載需保留來源!

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

主站蜘蛛池模板: 瑞昌市| 瑞昌市| 沛县| 湛江市| 卢湾区| 富川| 平定县| 乌拉特后旗| 诸城市| 辽阳市| 阳曲县| 丹棱县| 富阳市| 景洪市| 固阳县| 北流市| 鄂尔多斯市| 新沂市| 讷河市| 永春县| 阳谷县| 桂阳县| 临泉县| 仙游县| 土默特右旗| 温州市| 桐庐县| 澄江县| 石屏县| 阳东县| 宝山区| 吴堡县| 合肥市| 图木舒克市| 承德市| 扎鲁特旗| 湛江市| 蕲春县| 遵化市| 和静县| 伊通|