Home > Backend Development > PHP Tutorial > PHP picture counter code (enhanced version)

PHP picture counter code (enhanced version)

WBOY
Release: 2016-07-25 08:59:05
Original
922 people have browsed it
  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 $result = $str[$i];
  18. $result = '';
  19. echo $result;
  20. }
  21. for($j=0;$j<$len;$j++){
  22. $result = $new[$j];
  23. switch($result){
  24. case 0 :
  25. $ret[$j]='images/0.png';
  26. break;
  27. case 1 :
  28. $ret[$j]='images/1.png';
  29. break;
  30. case 2 :
  31. $ret[$j]='images/2.png';
  32. break;
  33. case 3 :
  34. $ret[$j]='images/3.png';
  35. break;
  36. case 4 :
  37. $ret[$j]='images/4.png';
  38. break;
  39. case 5 :
  40. $ret[$j]='images/5.png';
  41. break;
  42. case 6 :
  43. $ret[$j]='images/6.png';
  44. break;
  45. case 7 :
  46. $ret[$j]='images/7.png';
  47. break;
  48. case 8 :
  49. $ret[$j]='images/8.png';
  50. break;
  51. case 9 :
  52. $ret[$j]='images/9.png';
  53. break;
  54. } //by bbs.it-home.org
  55. echo '';
  56. }
  57. ?>
复制代码

以上代码中,为实现页面刷新预览,注释掉了session会话,以避免网页的重复刷新。 相比php文本计数器,这个计数器代码比较完善且实用。

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

大家也可以自己去一些素材网站上,查找一些好看的计数器图片,把显示图片做的专业些哦。



source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template