用PHP程序?qū)崿F(xiàn)隨機(jī)廣告圖片顯示_PHP教程
教程Tag:暫無Tag,歡迎添加,賺取U幣!
推薦:用PHP實(shí)現(xiàn)網(wǎng)頁開發(fā)中的翻頁跳轉(zhuǎn)我們都知道用 php mysql 在 web 頁實(shí)現(xiàn)數(shù)據(jù)庫資料全部顯示是非常簡單而有趣的,數(shù)據(jù)庫資料很少的情況下頁面顯示還是讓人滿意的,但是當(dāng)數(shù)據(jù)庫資料非常多的情況下,頁面的顯示情況將會變的非常糟
| 以下為引用的內(nèi)容: <?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ī)顯示序號$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;} } ####紀(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
| 以下為引用的內(nèi)容: ########每個(gè)廣告代碼之間用'#'隔開,display為顯示加權(quán)數(shù),越大顯示次數(shù)越多###### display=10 <a href="廣告1連接地址"> <img src="/images/banner/mb5ucomad1.gif" alt="廣告1"> </a> ################################ display=10 <a href="廣告2連接地址" target=_blank> <img src="/images/banner/mb5ucomad2.gif" width="468" height="60" alt="廣告2" border="0"></a> |
調(diào)用<?php myads();?>即可
分享:PHP網(wǎng)站開發(fā)中關(guān)于包含路徑問題的解決方案引言: 關(guān)于PERL與PHP中的包含路徑一直是一個(gè)比較難解的問題,主要是與操作系統(tǒng)和WEB服務(wù)器有關(guān),不可能非常智能化的解決這個(gè)路徑問題。相對于PERL,PHP的路徑好得多,解決起來也容易得多,因
相關(guān)PHP教程:
- PHPNOW安裝Memcached擴(kuò)展方法詳解
- php記錄頁面代碼執(zhí)行時(shí)間
- PHP中獎(jiǎng)概率的抽獎(jiǎng)算法程序代碼
- apache設(shè)置靜態(tài)文件緩存方法介紹
- php對圖像的各種處理函數(shù)代碼小結(jié)
- PHP 關(guān)于訪問控制的和運(yùn)算符優(yōu)先級介紹
- 關(guān)于PHP語言構(gòu)造器介紹
- php/js獲取客戶端mac地址的實(shí)現(xiàn)代碼
- php5.5新數(shù)組函數(shù)array_column使用
- PHP preg_match的匹配多國語言的技巧
- php 中序列化和json使用介紹
- php采集文章中的圖片獲取替換到本地
- 相關(guān)鏈接:
- 教程說明:
PHP教程-用PHP程序?qū)崿F(xiàn)隨機(jī)廣告圖片顯示
。