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” “https://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd”>  

<html xmlns=”https://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>  

  

<p 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” />  

  

  

<p class=”clear”></p>  

  

</form>  

  

<h3 class=”timeline”>freejs.net</h3>  

  

<ul class=”statuses”><?php echo $timeline?></ul>  

  

  

</p>  

  

</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> 

    <p 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).’ 

    <p class=”date”>’.strtotime($updatetime).'</p> 

    </p> 

    <p class=”clear”></p> 

    </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());  

  

?>