假如页面统计只需要记录统计数值,不记录其他具体的数据时,这时没有必要使用数据库进行记录,可以直接将统计数值存放到文本文件中。当然,这不是最好的方式,不过这是最简单的方式。
index.html
<!DOCTYPE html><html lang="zh-cn"><head> <meta charset="utf-8"> <meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no" name="viewport"> <meta content="yes" name="apple-mobile-web-app-capable"> <meta content="black" name="apple-mobile-web-app-status-bar-style"> <meta content="telephone=no" name="format-detection"> <meta content="email=no" name="format-detection"> <title>statistics</title> <style> html, body{ width: 100%; margin: 0; padding: 0; overflow-x: hidden; overflow-y: auto; font-family: 'Microsoft Yahei'; text-align: center; } .btn{ width: 30%; height: 30px; line-height: 30px; border-radius: 4px; background-color: #428bca; font-size: 18px; display: inline-block; } </style></head><body> <h1>页面统计</h1> <div class="btn" id="btn_click">点击</div> <div class="btn" id="btn_forward">转发</div> <script> var btn_click = document.querySelector('#btn_click'), btn_forward = document.querySelector('#btn_forward'), hasTouch = 'ontouchstart' in window; tapend = hasTouch ? 'touchend' : 'mouseup'; btn_click.addEventListener(tapend, function(){ statistics('click'); }, false); btn_forward.addEventListener(tapend, function(){ statistics('forward'); }, false); function statistics(action){ var url = 'http://localhost/statistics/interfaces/statistics.php?action='+action, script = document.createElement('script'); script.setAttribute('src', url); document.querySelector('head').appendChild(script); } </script></body></html>statistics.php
<?php $action = @$_GET['action']; function statistics($action){ $filename = $action.'_statistics.txt'; if(file_exists($filename)){ $count = file_get_contents($filename); file_put_contents($filename, ++$count); }else{ file_put_contents($filename, 1); } } if($action === 'click'){ statistics('click'); }else if($action === 'forward'){ statistics('forward'); }
版权声明:本文为博主原创文章,未经博主允许不得转载。
华友协同办公管理系统(华友OA),基于微软最新的.net 2.0平台和SQL Server数据库,集成强大的Ajax技术,采用多层分布式架构,实现统一办公平台,功能强大、价格便宜,是适用于企事业单位的通用型网络协同办公系统。 系统秉承协同办公的思想,集成即时通讯、日记管理、通知管理、邮件管理、新闻、考勤管理、短信管理、个人文件柜、日程安排、工作计划、工作日清、通讯录、公文流转、论坛、在线调查、
0
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号