TheBram
Legacy Member
ik heb een chatbox gevonden op deze site. Nu werkt die wel in IE maar niet in FF
hij staat op deze site: http://foxydata.d-free.eu
hier is mn code:
CSS:
Ajax
PHP
Als iemand hier wijs uit geraakt
maar ik althans niet
hij staat op deze site: http://foxydata.d-free.eu
hier is mn code:
CSS:
Code:
input, textarea { font-family: verdana; color:white; background:darkgreen; font-size: 13px; }
#content { width:500px; text-align:left; margin-left:10px; }
#chatwindow { border:0px solid #aaaaaa; padding:4px; background:#232D2F; color:white; width:450px; height:auto; font-family:courier new;}
#chatnick { border: 1px solid #00dd00; padding:4px; background:darkgreen;}
#chatmsg { border: 1px solid #00dd00; padding:4px; background:darkgreen; }
Ajax
Code:
<div id="content">
<p id="chatwindow"> </p>
<!-- <textarea id="chatwindow" rows="19" cols="95" readonly></textarea><br>
-->
<input id="chatnick" type="text" size="9" maxlength="12" >
<input id="chatmsg" type="text" size="40" maxlength="80" onkeyup="keyup(event.keyCode);">
<input type="button" value="Zend" onclick="submit_msg();" style="cursor:pointer;border:1px solid #00dd00;"><br><br>
<br>
</div>
<script type="text/javascript">
/****************************************************************
* Most Simple Ajax Chat Script (www.linuxuser.at) *
* Version: 3.1 *
* *
* Author: Chris (chris[at]linuxuser.at) *
* Contributors: Derek, BlueScreenJunky (http://forums.linuxuser.at/viewtopic.php?f=6&t=17)
* *
* Licence: GPLv2 *
****************************************************************/
/* Settings you might want to define */
var waittime=800;
/* Internal Variables & Stuff */
chatmsg.focus()
document.getElementById("chatwindow").innerHTML = "loading...";
var xmlhttp = false;
var xmlhttp2 = false;
/* Request for Reading the Chat Content */
function ajax_read(url) {
if(window.XMLHttpRequest){
xmlhttp=new XMLHttpRequest();
if(xmlhttp.overrideMimeType){
xmlhttp.overrideMimeType('text/xml');
}
} else if(window.ActiveXObject){
try{
xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
try{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
} catch(e){
}
}
}
if(!xmlhttp) {
alert('Giving up :( Cannot create an XMLHTTP instance');
return false;
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState==4) {
document.getElementById("chatwindow").innerHTML = xmlhttp.responseText;
zeit = new Date();
ms = (zeit.getHours() * 24 * 60 * 1000) + (zeit.getMinutes() * 60 * 1000) + (zeit.getSeconds() * 1000) + zeit.getMilliseconds();
intUpdate = setTimeout("ajax_read('chat.txt?x=" + ms + "')", waittime)
}
}
xmlhttp.open('GET',url,true);
xmlhttp.send(null);
}
/* Request for Writing the Message */
function ajax_write(url){
if(window.XMLHttpRequest){
xmlhttp2=new XMLHttpRequest();
if(xmlhttp2.overrideMimeType){
xmlhttp2.overrideMimeType('text/xml');
}
} else if(window.ActiveXObject){
try{
xmlhttp2=new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
try{
xmlhttp2=new ActiveXObject("Microsoft.XMLHTTP");
} catch(e){
}
}
}
if(!xmlhttp2) {
alert('Giving up :( Cannot create an XMLHTTP instance');
return false;
}
xmlhttp2.open('GET',url,true);
xmlhttp2.send(null);
}
/* Submit the Message */
function submit_msg(){
nick = document.getElementById("chatnick").value;
msg = document.getElementById("chatmsg").value;
if (nick == "") {
check = prompt("please enter username:");
if (check === null) return 0;
if (check == "") check = "anonymous";
document.getElementById("chatnick").value = check;
nick = check;
}
document.getElementById("chatmsg").value = "";
ajax_write("w.php?m=" + msg + "&n=" + nick);
}
/* Check if Enter is pressed */
function keyup(arg1) {
if (arg1 == 13) submit_msg();
}
/* Start the Requests! ;) */
var intUpdate = setTimeout("ajax_read('chat.txt')", waittime);
</script>
PHP
Code:
<?php
/* author: chris at linuxuser.at
licence: GPLv2
*/
$fn = "chat.txt";
$maxlines = 18;
$nick_length = 9;
/* Set this to a minimum wait time between posts (in sec) */
$waittime_sec = 0;
/* spam keywords */
$spam[] = "nigger";
$spam[] = "cum";
$spam[] = "dick";
$spam[] = "EAT coon";
/* IP's to block */
$blockip[] = "72.60.167.89";
/* spam, if message IS exactly that string */
$espam[] = "ajax";
/* Get Message & Nick from the Request and Escape them */
$msg = $_REQUEST["m"];
$msg = htmlspecialchars(stripslashes($msg));
$n = $_REQUEST["n"];
$n = htmlspecialchars(stripslashes($n));
if (strlen($n) >= $nick_length) {
$n = substr($n, 0, $nick_length);
} else {
for ($i=strlen($n); $i<$nick_length; $i++) $n .= " ";
}
if ($waittime_sec > 0) {
$lastvisit = $_COOKIE["lachatlv"];
setcookie("lachatlv", time());
if ($lastvisit != "") {
$diff = time() - $lastvisit;
if ($diff < 5) { die(); }
}
}
if ($msg != "") {
if (strlen($msg) < 2) { die(); }
if (strlen($msg) > 3) {
/* Smilies are ok */
if (strtoupper($msg) == $msg) { die(); }
}
if (strlen($msg) > 150) { die(); }
if (strlen($msg) > 15) {
if (substr_count($msg, substr($msg, 6, 8)) > 1) { die(); }
}
foreach ($blockip as $a) {
if ($_SERVER["REMOTE_ADDR"] == $a) { die(); }
}
$mystring = strtoupper($msg);
foreach ($spam as $a) {
if (strpos($mystring, strtoupper($a)) === false) {
/* Everything Ok Here */
} else {
die();
}
}
foreach ($espam as $a) {
if (strtoupper($msg) == strtoupper($a)) { die(); }
}
$handle = fopen ($fn, 'r');
$chattext = fread($handle, filesize($fn)); fclose($handle);
$arr1 = explode("\n", $chattext);
if (count($arr1) > $maxlines) {
/* Pruning */
$arr1 = array_reverse($arr1);
for ($i=0; $i<$maxlines; $i++) { $arr2[$i] = $arr1[$i]; }
$arr2 = array_reverse($arr2);
} else {
$arr2 = $arr1;
}
$chattext = implode("\n", $arr2);
if (substr_count($chattext, $msg) > 2) { die(); }
$out = $chattext . $n . " | " . $msg . "<br>\n";
$out = str_replace("\'", "'", $out);
$out = str_replace("\\\"", "\"", $out);
$handle = fopen ($fn, 'w'); fwrite ($handle, $out); fclose($handle);
}
?>
Als iemand hier wijs uit geraakt