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());
- ?>
相关推荐
周公周金桥 2020-09-06
大象从不倒下 2020-07-31
AlisaClass 2020-07-19
MaureenChen 2020-04-21
xingguanghai 2020-03-13
teresalxm 2020-02-18
木四小哥 2013-05-14
SoShellon 2013-06-01
Simagle 2013-05-31
羽化大刀Chrome 2013-05-31
waterv 2020-01-08
LutosX 2013-07-29
vanturman 2013-06-27
wutongyuq 2013-04-12
luoqu 2013-04-10
today0 2020-09-22
89520292 2020-09-18
bigname 2020-08-25