php jquery 无刷新评论
php jquery 无刷新评论
刷新后删除一个小时前的记录
php jquery 无刷新评论
演示
XML/HTML Code
<?php
define('INCLUDE_CHECK',1);
require "functions.php";
require "conn.php";
// remove tweets older than 1 hour to prevent spam
mysql_query("DELETE FROM add_delete_record WHERE id>1 AND updatetime<SUBTIME(NOW(),'0 1:0:0')");
//fetch the timeline
$q = mysql_query("SELECT * FROM add_delete_record ORDER BY ID DESC");
$timeline='';
while($row=mysql_fetch_assoc($q))
{
$timeline.=formatTweet($row['text'],$row['updatetime']);
}
// fetch the latest tweet
$lastTweet = '';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>php jquery 无刷新评论 www.freejs.net</title>
<link rel="stylesheet" type="text/css" href="demo.css" />
<script type="text/javascript" src="../../js/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<div id="twitter-container">
<form id="tweetForm" action="submit.php" method="post">
<span class="counter">140</span>
<label for="inputField">请留言测试</label>
<textarea name="inputField" id="inputField" tabindex="1" rows="2" cols="40"></textarea>
<input class="submitButton inact" name="submit" type="submit" value="提交" disabled="disabled" />
<div class="clear"></div>
</form>
<h3 class="timeline">Freejs.net</h3>
<ul class="statuses"><?php echo $timeline?></ul>
</div>
</body>
</html>
functions.php
PHP Code
<?php
if(!defined('INCLUDE_CHECK')) die('You are not allowed to execute this file directly');
function formatTweet($tweet,$updatetime)
{
$tweet=htmlspecialchars(stripslashes($tweet));
$flag = mt_rand(1,9);
return'
<li>
<a href="#"><img class="avatar" src="img/lito_s-ido_0'.$flag.'.png" width="48" height="48" /></a>
<div class="tweetTxt">
<strong><a href="#">demo</a></strong> '. preg_replace('/((?:http|https|ftp):////(?:[A-Z0-9][A-Z0-9_-]*(?:/.[A-Z0-9][A-Z0-9_-]*)+):?(/d+)?//?[^/s/"/']+)/i','<a href="$1" rel="nofollow" target="blank">$1</a>',$tweet).'
<div class="date">'.strtotime($updatetime).'</div>
</div>
<div class="clear"></div>
</li>';
}
?>
submit.php
PHP Code
<?php
define('INCLUDE_CHECK',1);
require "functions.php";
require "conn.php";
if(ini_get('magic_quotes_gpc'))
$_POST['inputField']=stripslashes($_POST['inputField']);
$_POST['inputField'] = mysql_real_escape_string(strip_tags($_POST['inputField']),$lr);
if(mb_strlen($_POST['inputField']) < 1 || mb_strlen($_POST['inputField'])>140)
die("0");
mysql_query("INSERT INTO add_delete_record SET text='".$_POST['inputField']."',updatetime=NOW()");
if(mysql_affected_rows($lr)!=1)
die("0");
echo formatTweet($_POST['inputField'],time());
?>
>更多相关文章
- 02-25谷歌推行Tango 3D智能视效手机开发项目
- 12-22php $_server应用
- 12-22PHP 解决一次因压缩代码引发的死循环
- 12-22php jquery 多文件上传
- 12-22该如何使用thinkphp分表呢?
- 12-22thinkPHP模板的输出和模型的使用
首页推荐
佛山市东联科技有限公司一直秉承“一切以用户价值为依归
- 01-11全球最受赞誉公司揭晓:苹果连续九年第一
- 12-09罗伯特·莫里斯:让黑客真正变黑
- 12-09谁闯入了中国网络?揭秘美国绝密黑客小组TA
- 12-09警示:iOS6 惊现“闪退”BUG
- 12-05亚马逊推出新一代基础模型 任意模态生成大模
- 12-05OpenAI拓展欧洲业务 将在苏黎世设立办公室
- 12-05微软质疑美国联邦贸易委员会泄露信息 督促其
- 12-05联交所取消宝宝树上市地位 宝宝树:不会对公
- 12-04企业微信致歉:文档打开异常已完成修复
相关文章
24小时热门资讯
24小时回复排行
热门推荐
最新资讯
操作系统
黑客防御