...

View Full Version : smart refresh to my script



bbmak
09-10-2005, 07:05 PM
I try to do a smart refresh to my chat room; however, i can't get it work
My chat room is similar to shoutbox.

I try to use the reference from this page to do the smart refresh.
http://codewalkers.com/tutorials/87/2.html

One of my biggest problem is that i don't know java script, i only can come up stuffs with php, so if there anyone can subtitute the php, that will be good.


here is my script input message script

<?
error_reporting(E_ALL);
session_start();
header("Cache-control: private");

if (!isset($_SESSION['user_login']) || $_SESSION['user_login'] !== true) {
header('Location: auth.php?action=login');
exit;
}


//make register_globals off
if (ini_get('register_globals')) {
$superglobals = array($_SERVER, $_ENV,
$_FILES, $_COOKIE, $_POST, $_GET);
if (isset($_SESSION)) {
array_unshift($superglobals, $_SESSION);
}
foreach ($superglobals as $superglobal) {
foreach ($superglobal as $global => $value) {
unset($GLOBALS[$global]);
}
}
ini_set('register_globals', false);
}
//make register_globals off


?>
<?php


$users = $_SESSION['username'];
$user_id = $_SESSION['user_id'];
?>

<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<form method="post" action="message.php">
<input type="hidden" NAME="username" value="<? echo "$users"; ?>">
Message: <input type="text" NAME="message" value="" size="60">
<input type="submit" name="submit" value="submit"> <a href="auth.php?action=logout&user_id=<? echo $user_id; ?>" target="_parent">Logout</a>
</form>
</html>



Here is my message windows script

<?
session_start();
if (!isset($_SESSION['user_login']) || $_SESSION['user_login'] !== true) {
header('Location: auth.php?action=login');
exit;
}

//make register_globals off
if (ini_get('register_globals')) {
$superglobals = array($_SERVER, $_ENV,
$_FILES, $_COOKIE, $_POST, $_GET);
if (isset($_SESSION)) {
array_unshift($superglobals, $_SESSION);
}
foreach ($superglobals as $superglobal) {
foreach ($superglobal as $global => $value) {
unset($GLOBALS[$global]);
}
}
ini_set('register_globals', false);
}
//make register_globals off

include ('connect.php');
$conn = include ('connect.php');
echo '<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">';






if ($_SERVER['REQUEST_METHOD'] == 'POST')
{

include ('connect.php');
$username = mysql_real_escape_string($_POST['username']);
$message = mysql_real_escape_string($_POST['message']);



if (empty($_POST['message']))
{
echo "You did not enter any message<br \>";
exit;
}

$query = "INSERT INTO chatroom (username, message, msgdate) VALUES ('$username', '$message', NOW())";
$result = mysql_query($query) or die('Error in artist query: ' . mysql_error());
@mysql_query ($result, $conn);

$mytime = time();
touch ('sar.pid', $mytime);
setcookie ('pid', $mytime, time()+(60*60));
$redir = dirname('http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'])
. '/input.php';
Header ('Location:'.$redir);
exit();

}





//bad word function
function badword($message)
{

$fp = fopen("badwords.txt", "r");
while($line = fgets($fp)) {
list($bad,$good) = explode("|", $line);
$badwords[$bad] = $good;

$filter = array($bad => $good);


foreach ($filter as $bad => $good)
{



$message = str_replace("$bad", "$good", $message);
}

}

return $message;
}
//bad word function
?>


<script language='JavaScript1.2'>
<!--
function sar(mytime)
{
img = new Image;
img.src = 'detector.php';
pid = read_cookie('pid');
if (pid > mytime)
{
var mytime = pid;
write_cookie ('mytime', mytime, 1);
document.location.href = 'message.php';
}
setTimeout('sar('+ mytime +')', 2000);
}
function read_cookie (name)
{
var cookieValue = "";
var search = name + "=";
if(document.cookie.length > 0)
{
offset = document.cookie.indexOf(search);
if (offset != -1)
{
offset += search.length;
end = document.cookie.indexOf(";", offset);
if (end == -1) end = document.cookie.length;
cookieValue = unescape(document.cookie.substring(offset, end))
}
}
return cookieValue;
}
function write_cookie(name, value, hours)
{
var expire = "";
if(hours != null)
{
expire = new Date((new Date()).getTime() + hours * 3600000);
expire = "; expires=" + expire.toGMTString();
}
document.cookie = name + "=" + escape(value) + expire;
}
function start(mytime)
{
write_cookie ('mytime', mytime, 1);
sar (mytime);
}
start (<?=time();?>);
-->
</script>




<?
$query = "SELECT * FROM chatroom ORDER BY msgdate DESC LIMIT 0,30";
$result = mysql_query($query);
if (mysql_num_rows($result) >= 1)
{


while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$message = $row['message'];
$username = $row['username'];

echo "[" . $username . "]", badword($message), "<br>";
}

}

?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum