I'm using the tutorial from this site here http://www.aspektas.com/blog/an-ajax-shoutbox And I put everything together. But I'm getting an error.
Code: Select all
Fatal error: Call to undefined function fcontrol() in /home/insight/public_html/modules/shoutbox/shout.php on line 3Anyway the code is here:
index.php (code imbedded into my index.php file that shows the input box and shout messages)
Code: Select all
<p id="shoutbox"><?php include("modules/shoutbox/getshouts.php"); ?></p>
<form action="" method="post" onsubmit="return push_shout()">
<input type="text" name="user" id="user" />
<input type="text" name="shout" id="shout" />
<input type="submit" value="Shout" />
</form>
<p id="console"></p>Code: Select all
<?php
include("include/constants.php");
$sql=mysql_connect(DB_SERVER, DB_USER, DB_PASS) or die(mysql_error());
mysql_select_db(DB_NAME, $sql) or die(mysql_error());
?>Code: Select all
<?php
require_once("modules/shoutbox/config.php");
echo implode(mysql_fetch_assoc(mysql_query("SELECT COUNT(id) FROM shout")));
?>Code: Select all
<?php
require_once("modules/shoutbox/config.php");
$result = mysql_query("SELECT * FROM shout ORDER BY id DESC LIMIT 10");
$lines = array();
while ($shout = mysql_fetch_assoc($result)) {
$lines[] = "{$shout['username']} (" .
date("H:i:s", $shout['datetime']) .
") :: {$shout['shout']}<br />";
}
echo implode(array_reverse($lines));
?>Code: Select all
<?php
require_once("modules/shoutbox/config.php");
if (fcontrol("shout", 5)) {
$user = mysql_real_escape_string($_POST['user']);
$shout = mysql_real_escape_string($_POST['shout']);
$user = htmlspecialchars($user);
$shout = htmlspecialchars($shout);
mysql_query("INSERT INTO shout (username, datetime, shout)
VALUES ('$user', " . time() . ", '$shout')");
} else echo "Please wait...";
?>Code: Select all
var current_shouts = 0;
function $(eleid) {
return document.getElementById(eleid);
}
function urlencode(u) {
u = u.toString();
var matches = u.match(/[\x90-\xFF]/g);
if (matches) {
for (var mid = 0; mid < matches.length; mid++) {
var char_code = matches[mid].charCodeAt(0);
u = u.replace(matches[mid], '%u00' + (char_code & 0xFF).toString(16).toUpperCase());
}
}
return escape(u).replace(/\+/g, "%2B");
}
function shouts() {
clearTimeout(getshout);
var xmlHttp = (window.XMLHttpRequest) ? new XMLHttpRequest : new ActiveXObject("Microsoft.XMLHTTP");
xmlHttp.open("GET", "modules/shoutbox/shouts.php?i=" + Math.random());
xmlHttp.onreadystatechange = function() {
if (this.readyState == 4) {
if (parseInt(this.responseText) > current_shouts) {
getshouts();
current_shouts = parseInt(this.responseText);
}
getshout = setTimeout("shouts()", 1000);
}
}
xmlHttp.send(null);
}
function getshouts() {
var xmlHttp = (window.XMLHttpRequest) ? new XMLHttpRequest : new ActiveXObject("Microsoft.XMLHTTP");
xmlHttp.open("GET", "modules/shoutbox/getshouts.php?i=" + Math.random());
xmlHttp.onreadystatechange = function() {
if (this.readyState == 4) $("shoutbox").innerHTML = this.responseText;
}
xmlHttp.send(null);
}
function shout() {
var xmlHttp = (window.XMLHttpRequest) ? new XMLHttpRequest : new ActiveXObject("Microsoft.XMLHTTP");
xmlHttp.open("POST", "modules/shoutbox/shout.php");
var data = "user=" + urlencode($("user").value) + "&" + "shout=" + urlencode($("shout").value);
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", data.length);
xmlHttp.onreadystatechange = function() {
if (this.readyState == 4) {
if (!this.responseText) $("shout").value = "";
else {
$("console").innerHTML = this.responseText;
setTimeout("$('console').innerHTML = ''", 5000);
}
getshouts();
}
}
xmlHttp.send(data);
return true;
}
var getshout = setTimeout("shouts()", 1000);