php圖片計數器代碼(增強版)

來源:互聯網
上載者:User
  1. //session_start();
  2. $dir = 'cookie.txt';
  3. $file = fopen($dir,'r');
  4. $content = fgets($file);
  5. fclose($file);
  6. //if(empty($_SESSION['viewer'])){
  7. $content++;
  8. $newopen = fopen($dir,'w');
  9. fwrite($newopen,$content);
  10. fclose($newopen);
  11. //$_SESSION['viewer'] = 1;
  12. //}
  13. //echo "網站的訪問次數:{$content}";
  14. $new = strval($content); //轉化為字串
  15. $len = strlen($new);
  16. $str = str_repeat('0',6-$len);
  17. for($i=0;$i
  18. $result = $str[$i];
  19. $result = '';
  20. echo $result;
  21. }
  22. for($j=0;$j<$len;$j++){
  23. $result = $new[$j];
  24. switch($result){
  25. case 0 :
  26. $ret[$j]='images/0.png';
  27. break;
  28. case 1 :
  29. $ret[$j]='images/1.png';
  30. break;
  31. case 2 :
  32. $ret[$j]='images/2.png';
  33. break;
  34. case 3 :
  35. $ret[$j]='images/3.png';
  36. break;
  37. case 4 :
  38. $ret[$j]='images/4.png';
  39. break;
  40. case 5 :
  41. $ret[$j]='images/5.png';
  42. break;
  43. case 6 :
  44. $ret[$j]='images/6.png';
  45. break;
  46. case 7 :
  47. $ret[$j]='images/7.png';
  48. break;
  49. case 8 :
  50. $ret[$j]='images/8.png';
  51. break;
  52. case 9 :
  53. $ret[$j]='images/9.png';
  54. break;
  55. } //by bbs.it-home.org
  56. echo '';
  57. }
  58. ?>
複製代碼

以上代碼中,為實現頁面重新整理預覽,注釋掉了session會話,以避免網頁的重複重新整理。相比php文本計數器,這個計數器代碼比較完善且實用。

附,圖片素材的下載地址:http://liangqi000.googlecode.com/files/image-counter.rar

大家也可以自己去一些素材網站上,尋找一些好看的計數器圖片,把顯示圖片做的專業些哦。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.