论坛新帖提醒工具
Jun 06, 2016 pm 08:08 PM直接切入正题,使用PHP+HTML5开发论坛新帖实时提醒工具。 看看开发思路: 为了保证浏览器最小化也能收到消息提醒,需要用到HTML5的Notifications特性,推荐阅读: Notifications桌面提醒 http://www.1990c.com/?p=833 下面以监控admin5论坛任务区一个版块为例:
直接切入正题,使用PHP+HTML5开发论坛新帖实时提醒工具。
看看开发思路:
为了保证浏览器最小化也能收到消息提醒,需要用到HTML5的Notifications特性,推荐阅读:
Notifications桌面提醒
http://www.1990c.com/?p=833
下面以监控admin5论坛任务区一个版块为例:
<!--编码与目标站一致--> 新帖提醒工具 //请求桌面通知权限 function init() { if (window.webkitNotifications) { window.webkitNotifications.requestPermission(); } } //消息提醒 function notify(str){ var icon = "logo.png"; //图标路径 var title = "新帖提醒("+ time + "秒后自动关闭)"; //消息标题 var body = str; //消息内容 var popup = window.webkitNotifications.createNotification(icon, title, body); popup.show(); //显示消息 } //刷新页面 function refresh() { document.location.reload(); } <?php $url = "http://bbs.admin5.com/forum-560-1.html"; //目标版块 $sleep = 5000; //监控频率(5秒) if(empty($_SESSION['title'])) { //首次抓取 $str = file_get_contents($url); preg_match_all('/onclick=\"atarget\(this\)\" class=\"xst\" >(.*)/',$str,$titleData); $_SESSION['title'] = $titleData[1]; //抓取帖子标题存入SESSION帖子数组 echo "setTimeout('refresh()',$sleep)"; //刷新页面 } else { //非首次抓取 date_default_timezone_set('PRC'); $now = mktime(); //计算当前时间 $str = file_get_contents($url); preg_match_all('/onclick=\"atarget\(this\)\" class=\"xst\" >(.*)/',$str,$title); //抓取帖子标题 preg_match_all('/(.*)/',$str,$time); //抓取发帖时间 foreach($title[1] as $k => $v) { if(!in_array($v,$_SESSION['title'])) { //判断是否为新帖子 if(($now - strtotime($time[2][$k])) <!--消息提醒--> notify("<?php echo $v;?>"); <?php } } } unset($_SESSION['title']); //清空SESSION标题数组 $_SESSION['title'] = $title[1]; //将新抓取的标题数组存入SESSION标题数组 echo "setTimeout('refresh()',$sleep)"; //刷新页面 } ?>
为了方便阅读,代码已经精简,各位可以根据实际需求修改,此外,使用Ajax也是一个不错的方法,欢迎交流。
原文地址:论坛新帖提醒工具, 感谢原作者分享。

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Ouyi Exchange app domestic download tutorial

Ouyi official website registration portal 2025

Detailed explanation of the issuance price and issuance time of LOOM coins

The latest registration portal for Ouyi official website 2025

Top 10 Digital Virtual Currency Trading Platforms Ranking 2025 Latest

Top 10 virtual currency trading apps rankings The top ten currency trading platforms in 2025

Top 10 Global Security and Easy-to-use Virtual Currency Exchange Rankings 2025

Ranking of safe and reliable digital currency exchange apps in 2025
