######## #随机广告显示 ##########
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 and display count to array $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);
}
?>
Ad code file Ads.txt
####### #每个广告代码之间用 ' # ', display is a weighted number, the larger the number of displays ################
################################
display=10
################################
display=10
Call Can
The above describes the Photoshop CS5 official Chinese cracked version of the download PHP implementation of random AD display code, including the Photoshop CS5 the official Chinese version of the download of the content, I hope that the PHP tutorial interested in a friend helpful.