phpjquery无刷新评说
时间:2021-07-01 10:21:17
帮助过:3人阅读
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?=?'';??
- ??
-
?>??
- ??
- >??
-
<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.nettitle>??
- ??
-
<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">140span>??
-
<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.neth3>??
- ??
-
<ul?class="statuses">php?echo?$timeline?>ul>??
- ??
- ??
-
div>??
- ??
-
body>??
-
html>??
?functions.php
?
PHP Code
-
- ??
-
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'?
-
?????
-
????.$flag.'.png"?width="48"?height="48"?/>?
-
?????
-
????demo?'.?preg_replace('/((?:http|https|ftp):\/\/(?:[A-Z0-9][A-Z0-9_-]*(?:\.[A-Z0-9][A-Z0-9_-]*)+):?(\d+)?\/?[^\s\"\']+)/i','$1',$tweet).'?
-
????'.strtotime($updatetime).'?
-
?????
-
?????
-
????
';??
- ??
- }??
- ??
- ?>??
submit.php
PHP Code
-
- ??
- 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());??
- ??
- ?>??
- ?
原文地址:http://www.freejs.net/article_biaodan_88.html