#########隨機廣告顯示##########
function myads(){
$dir="ads"; #設置存放記錄的目錄
//$dir="ads"; #設置存放記錄的目錄
$ads="$dir/ads.txt"; #設置廣告代碼文件
$log ="$dir/ads.log"; #設 " /> 午夜亚洲福利,97超碰在线免费,欧美精品一区二区三区国产精品

色尼玛亚洲综合影院,亚洲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函數),轉載需保留來源!

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

主站蜘蛛池模板: 盐亭县| 罗平县| 洛川县| 沙坪坝区| 连平县| 宁晋县| 三穗县| 清涧县| 高阳县| 太保市| 乌拉特中旗| 廊坊市| 朝阳县| 永宁县| 香港 | 阿荣旗| 福安市| 吉安市| 丰镇市| 荔浦县| 苗栗县| 玉溪市| SHOW| 青岛市| 新乡县| 平顶山市| 越西县| 尼木县| 宜川县| 静安区| 天峻县| 文山县| 禹州市| 邹城市| 寿光市| 红原县| 交口县| 邹平县| 仁布县| 紫金县| 南川市|