PGTibs Posted January 9, 2009 Share Posted January 9, 2009 I've got a small ajax simple chat on my website that consists of 3 webpages. I have found where i want to add the time but don't know what command to use that will show the current time of when it was posted and not the time it is at the moment the user is viewing the page? E.g. the time the message is sent other than the time it currently is. Properties File, contains text line. w.php <?php /* author: chris at linuxuser.at licence: GPLv2 */ $fn = "chat.txt"; $maxlines = 7; $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, ) > 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); } ?> chat.php <p id="chatwindow"> </p><div align="left"> <!-- <textarea id="chatwindow" rows="5" cols="95" readonly></textarea></div><br> --> <div align="center"><input id="chatnick" type="text" size="9" maxlength="9" > <input id="chatmsg" type="text" size="72" maxlength="90" onkeyup="keyup(event.keyCode);"> <input type="button" value="add" onclick="submit_msg();" style="color:white;cursor:pointer;border:1px solid black;background:black;"></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> Link to comment https://forums.phpfreaks.com/topic/140183-ajax-chat-command-to-add-time-of-post/ Share on other sites More sharing options...
PGTibs Posted January 9, 2009 Author Share Posted January 9, 2009 Posted in wrong section.. Sorry, can a mod move it please? Thanks Link to comment https://forums.phpfreaks.com/topic/140183-ajax-chat-command-to-add-time-of-post/#findComment-733566 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.