All articles(网络文学目录) All Pictures(图片目录) All Softwares(软件目录)

 
PHP实例:用PHP程序实现随机广告图片显示_[PHP教程]

Writer: 归海一刀 Article type: Programming skills(编程技巧) Time: 2014/2/17 7:33:35 Browse times: 433 Comment times: 0

PHP实例:用PHP程序实现随机广告图片显示_[PHP教程]


Head photo

banner
Go homepage
Upload pictures
Write articles

PHP实例:用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 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 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


################################
display=10

调用即可





There are 0 records,
Comment:
Must be registered users to comment(必须是注册用户才能发表评论)

Disclaimer Privacy Policy About us Site Map
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.