CMX Ads Webmaster Resources for Success

Websites, Advertising, Scripts Tips n Snippets

News: NSA Insider Reveal All

Chat room or shout box cgi perl or flatfile php script or a ajax and java script version.

Chat room or shout box flatfile php script.

Hi!. Here is a great chat/shout php script than can easily fit into any website. You can set width and height. I could have gone and made this more comprehensive but I wanted to keep it simple yet still have some features that are good to have. There is no js auto refresh in my experience after a certain amount of auto refresh on a shared server the page will come up blank. So a meta refresh is used. Its easy to add the header refresh if you want it. To use as an include remove the header html and closing body and html tags.

Features include:Note this is pure php no ajax used. See below for ajax chatroom link.
1 - text length limit
2 - multiple character limit
3 - text and periods only
4 - remove extra spaces
5 - allow or disallow links
6 - bad word filter
7 - referrer check
8 - set amount of posts to show(set for 20 now)
9 - and you can set the width and height(css) of the chat box.
10 - added scroll feature can set height in scroll css.
11 - added some new smileys.
12 - reserved names for admin moderator that display in red font. If user submits a reserved name the name will be changed to "user(random 4 digit number)".
13 - delete posts by going to shoutbox.php?admin and enter password. adds a delete link next to post
13 - enable or disable the captcha. if you have a login site no need for it.
14 - and a cool type of captcha I came up with too

Take a look at the base script and checkout the demo. Three are 3 files in the download and image folder. The main page shown here and the smiley function which I could have just added to the main page and the empty text file. Its free to download and I hope you find it useful! Thanks for stopping by!

Click here for the updated main shout script.

  1: <?php
2: session_start
();
3:
date_default_timezone_set('America/New_York');
4:
$self=$_SERVER["PHP_SELF"];
5: if(isset(
$_SERVER['HTTP_REFERER'])) $HTTP_REFERER $_SERVER['HTTP_REFERER'];
6: if(isset(
$_SERVER['HTTP_HOST'])) $HTTP_HOST $_SERVER['HTTP_HOST'];
7: if(isset(
$_SERVER['HTTP_USER_AGENT'])) $HTTP_USER_AGENT $_SERVER['HTTP_USER_AGENT'];
8:
//echo $HTTP_HOST;
9: //echo $HTTP_REFERER;
10:
$user_ip $_SERVER['REMOTE_ADDR'];
11:
$time date("[H:i:s]");
12:
$unixtime=time();
13: include 
"smiley.php";
14: function 
clean($text)
15: {
16:
$text strip_tags($text);
17:
$text htmlentities($textENT_QUOTES);
18:
$text trim($text);
19: return (
$text); //output clean text
20:
}
21:
22:
//SETTINGS
23: //file name
24:
$dbfile 'yourfilename.txt';
25:
26:
//set your admin password
27:
$adminpass='adminpass';
28:
$adminpass=sha1($adminpass);
29:
30:
//enable captcha set empty variable to 1
31:
$captcha '1';
32:
//check posts are from your domain
33:
$domain='www.example.com';
34:
//dont allow links = empty
35:
$links='1';
36:
//word wrap comments characters
37:
$wrap='100';
38:
//box width (pixels)
39:
$boxWidth 400;
40:
//maximum entries in box 
41:
$entries 20;
42:
// maximum text length
43:
$textLength ='200';
44:
//bad words filter
45:
$badwords = array('fuck''asshole''suck''sucks''cock');
46:
//set reserved admin names
47:
$reserved = array('cmxads''admin''moderator''king''almighty''webmaster');
48:
//must have referrer enabled 1 or empty no
49:
$enableRefererCheck='1';
50:
///////////////////////////////////////////
51:
if (isset($_GET['delete']) && isset($_GET['admin']) && !empty($_SESSION['admin'])) {
52:
$key clean($_GET['delete']);
53:
$fc=file($dbfile);
54:
$f=fopen('in_temp.txt','w');
55:
$temp = array();
56: foreach(
$fc as $line)
57: {
58:     if (
strpos($line,$key) === false
59:         
fwrite($f$line);
60: }
61:
fclose($f);
62:
unlink($dbfile);
63:
rename('in_temp.txt'$dbfile);
64: }
65:
66:
$self=clean($self);
67:
68: if(isset(
$_POST['admin']) && isset($_GET['admin']) && isset($_POST['password'])){
69:  
$pa=clean($_POST['password']);
70:  
$pa=sha1($pa);
71: if(
$pa == $adminpass){
72:
$_SESSION['admin']='loggedin';    
73: }
74: }
75:
////////////////////////////////////////////////////
76:
if($enableRefererCheck && !preg_match("/$HTTP_HOST/"$domain)){
77:
// return true;
78: //Referer Check
79:
echo 'Referrer Check block no host match error.';
80:  exit;    
81:
82:
83:   
// Delete repeated characters (more than 3 times)
84:   
function checkRepeats($str) {
85:     
$newstr substr($str03);
86:     for(
$i 3$i strlen($str); $i++) {
87:       if(
$str[$i] != $str[$i-1] || $str[$i] != $str[$i-2] || $str[$i] != $str[$i-3]) $newstr .= $str[$i];
88:     }
89:     return 
$newstr;
90:   }
91:
//////////////////////////////////////////  
92:    
function cutString($str$length) {
93:     if(
strlen($str) > $length) {
94:       
$words explode(' '$str);
95:       
$wCnt count($words);
96:
97:       if(
$wCnt == 1) {
98:         
$str substr($str0$length) . '.';
99:       }
100:       else {
101:         
$str '';
102:         
$cnt 0;
103:
104:         while(
$cnt $wCnt && strlen($str) < $length) {
105:           
$str .= trim($words[$cnt++]) . ' ';
106:         }
107:         if(
$cnt $wCnt$str .= '.';
108:       }
109:     }
110:     return 
$str;
111:   }
112:   
// Replace bad words with image
113:   // Arguments: text
114:   //
115:   
function replaceWords($str) {
116:     global 
$badwords;
117:     
$repl '<img src="images/angry.gif" border="0" width="31" height="20" align="absmiddle">';
118:     
$c '(\_|[^\d\w\r\n])*';
119:     
$cl strlen($c);
120:     for(
$i 0$i count($badwords); $i++) {
121:       
$expr chunk_split($badwords[$i], 1$c);
122:       
$str preg_replace('/' substr($expr0strlen($expr) - $cl) . '/i'$repl$str);
123:     }
124:     return 
$str;
125:   }
126:
///////////////////////////////////////////  
127:  
function randomNumber($length) {
128:     
$result '';
129:     for(
$i 0$i $length$i++) {
130:         
$result .= mt_rand(09);
131:     }
132:     return 
$result;
133:
134:
//////////////////////////////////////    
135:
function alphaNumSpacePeriod($c1
136: {
137:     
$c1=trim(preg_replace('/(\s)\s+/'' '$c1)); 
138:   return 
trim(preg_replace('/[^A-Za-z0-9\.]/'' ',$c1));
139:  
// return trim(preg_replace('/[^A-Za-z0-9\s]/', '',$c1));
140:
}
141:
////////////////////////////////////
142:
function alphaNumOnly($c
143: {
144:     return 
trim(preg_replace('/[^A-Za-z0-9]/''',$c));
145: }
146:
//////////////////////////////////
147:
function oneSpace($str
148: {
149:   return 
trim(preg_replace('/(\s)\s+/'' '$str));
150: }
151:
///////////////////////////////////// 
152:     
if(file_exists($dbfile)) {
153:      
$filesfile($dbfile);
154:       
$size filesize($dbfile);
155:       if(
$size 0) {
156: if(
$size $entries){       
157:
$output array_slice($files0,$entries);// returns lines set at line 30     
158:  
file_put_contents($dbfile$outputLOCK_EX);
159:  }else{
160:   
$output=$files;    
161: }
162:
$i=1;
163:
$cnt=count($output);
164:
//echo $cnt;
165:
$u='';
166:
$n='';
167:
$rt='';
168: foreach (
$output as $line) {
169:
$users explode('#'$line);
170:
$thename =$users[3];
171:
$comment =stripslashes(smile($users[4]));
172:
//uncomment below 3 lines to decode for hyperlinks with link name used
173: //if($links){
174: //$comment= html_entity_decode($comment, ENT_COMPAT | ENT_HTML5);
175: //}
176:
177:
$comment =wordwrap($comment$wrap"\n"1);
178:
179: if (!empty(
$_SESSION['admin'])) {
180:
$comment="$comment<br><a href=\"shoutbox.php?admin&delete=$users[0]\">Delete</a>";    
181: }
182:
183:
184: if (
in_array($thename$reserved)) { 
185:
186:      
$u .= "<span style=\"text-decoration:underline;color:red;\">$thename $users[2]</span><br>$comment<hr>";    
187:      
$rt='1';
188:     }
189:     else{
190:      
$u .= "<span style=\"text-decoration:underline;color:green;\">$thename $users[2]</span><br>$comment<hr>";            
191:     }
192:
193: if(empty(
$comment)){
194:
$u .= "<span style=\"color:red;\">No posts yet</span><br>$comment<hr>";    
195: }
196:
//$u .= "<br>";
197: //$n .= $users[1];
198: //$n .= "\n";
199:
$i++;
200: }
201:
202: }
203: }
204: if(empty(
$u)){
205:
$u '<span style="color:red;">No posts yet</span><br><hr>';    
206: }
207:
$admin_in='';
208:  
$errors='';
209: if (isset(
$_POST['postit'])){
210: if (isset(
$_POST['user']) and empty($_POST['user'])){
211:  
$errors='1';
212:  }elseif(!empty(
$_POST['user'])){
213:
$user clean($_POST['user']);
214: if (
strlen($user) > 12){
215:    
$user substr($user011);
216:    }
217:  
$user alphaNumOnly($user);
218:  
$user=strtolower($user);
219: if(empty(
$_SESSION['admin'])){
220:     if(
in_array($user,$reserved)){
221:         
$rn=randomNumber('4');
222:
$user="user".$rn;        
223:     }
224:  }
225:
$_SESSION['user']=$user;
226: }else{
227:
$user=$_SESSION['user'];    
228: }
229:
230:
231:
232:
////////////////////////////////////////////////////////
233:
if(isset($_POST['box']) and empty($_POST['box'])){
234:  
$errors='1';
235:  }else{
236:      
237:
$str=str_replace(array('script','#'),'',$_POST['box']);
238:
$str=checkRepeats($str);
239:
$str=cutString($str$textLength);
240:
$str=oneSpace($str);
241:  if(!
$links){
242:
$str clean($str);
243:
$str =alphaNumSpacePeriod($str);
244: }elseif(
$links){
245:
$str=strip_tags($str,'<a>');
246:
$str=htmlentities($str);
247: }else{
248:
$str=htmlentities($str);
249: }
250:
$str=str_replace("\n","<br>",$str);
251:
$str=replaceWords($str);
252: }
253:
///////////////////////////////////////
254:
if ($captcha) {
255:     
256: if(isset(
$_POST['m1']) and empty($_POST['m1'])){
257:  
$errors='1';
258:  }
259: if(isset(
$_POST['a1']) and empty($_POST['a1'])){
260:  
$errors='1';
261:  }
262:  if(!empty(
$_POST['a1']) and !empty($_POST['m1']) and $_POST['a1'] != $_POST['m1']){
263:  
$errors='1';
264:  }
265: }
266:
///////////////////////////////////
267:
268:
if (!file_exists($dbfile)) touch($dbfile);
269: if (!
$errors){
270:
$fh fopen($dbfile'r');
271:
$fcontent fread($fhfilesize($dbfile));
272: if(isset(
$_SESSION['user'])){
273:  
$suser=$_SESSION['user'];
274:  }else{
275:
$suser=$user;
276: }
277:
$newcontent="$unixtime#$user_ip#$time#$suser#$str\n";
278:
$_SESSION['posted']=$unixtime;
279:
$towrite $newcontent.$fcontent;
280:
$fh2 fopen($dbfile'w+');
281:
fwrite($fh2$towrite);
282:
fclose($fh);
283:
fclose($fh2);
284:
header("Location: $self");
285: }else{
286: echo 
'<p style="text-align:center;color:red;">Errors with your post.</p>';
287: }
288: }
289:
?> 
290: <!DOCTYPE html>
291: <html lang="en"><head>
292: <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
293: <title>Try out the CMXads easy chat and shout box its a free and cool text DB php script</title>
294: <meta name="copyright" content="cmxads content management xtendable advertising and design services">
295: <meta name="googlebot" content="noarchive"> 
296: <meta name="author" content="cmxads easy chat and shout text db php script">
297: <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
298: <meta name="description" content="The new cmxads kool easy chat and shout box text db flat file php script try it out easy to style and fit into any website just upload and its ready to go.">
299: <style type="text/css">
300: .cssPostText {
301:   font-family: Arial, Helvetica;
302:   font-size: 12px;
303:   color: #000000;
304:  padding-top: 5px;
305:   padding-bottom: 10px;
306:     background-color: #FFFFC0;
307:   border: 2px inset #EEEEEE;
308:  vertical-align:top;
309:  overflow-y: scroll; 
310: }
311:
312:     #scroll {
313: width:400px;
314: margin: 0 auto;
315:    height:350px;
316:     overflow-y: auto;
317:     scrollbar-arrow-color: blue;
318:     scrollbar-face-color: #e7e7e7;
319:     scrollbar-darkshadow-color: #888888;
320:     scrollbar-3dlight-color: #a0a0a0;
321: }
322:
323: </style>
324:
325:     <script type="text/javascript">
326:  //firefoxonly  // 
327: //scrollByLines and scrollByPages for else below //  
328:     
329:         var scrollTimer = null;
330:
331:         function ScrollUp () {
332:             var scrollArea = document.getElementById ("scroll");
333:             if (scrollArea.doScroll) {  // Internet Explorer
334:                 scrollArea.doScroll ("scrollbarDown");
335:             }
336:             else {
337:                 scrollArea.scrollTop += 10;
338:             }
339:         }
340:
341:         function ScrollDown () {
342:             var scrollArea = document.getElementById ("scroll");
343:             if (scrollArea.doScroll) {  // Internet Explorer
344:                 scrollArea.doScroll ("scrollbarUp");
345:             }
346:             else {
347:                 scrollArea.scrollTop -= 10;
348:             }
349:         }
350:
351:         function StartScroll (up) {
352:             StopScroll ();
353:             if (up) {
354:                 scrollTimer = setInterval (ScrollDown, 80);
355:             }
356:             else {
357:                 scrollTimer = setInterval (ScrollUp, 80);
358:             }
359:         }
360:
361:         function StopScroll () {
362:             if (scrollTimer !== null) {
363:                 clearTimeout (scrollTimer);
364:                 scrollTimer = null;
365:             }
366:         }
367:     </script>
368:
369: </head>
370: <body>
371:
372: <center>
373:
374:     <table style="-moz-border-radius : 8px;-webkit-border-radius : 8px;border-radius : 8px;" border="1" cellspacing="10" cellpadding="10" width="<?php echo $boxWidth?>">
375:     <tr>
376:     
377:     <td class="cssPostText"><div id="scroll"><?php echo $u?></div>
378:   <div style="width:400px;background-color:#e7e7e7;padding-top:10px;height:30px;"><button onmouseover="StartScroll (false)" onmouseout="StopScroll ()">Hover to Scroll down</button><button onmouseover="StartScroll (true)" onmouseout="StopScroll ()">Hover to Scroll up</button></div>  
379:     </td>
380:     
381:     </tr>
382:     <tr><td>
383: <span style="font-color:indigo;font-size:8pt;text-decoration:none;"><a target="_blank" href="http://www.cmxads.com/">CMXads.com Flatfile Free Script</a><img src="images/cmxdesignslogo2.gif" height="20px" align="right"></span>
384: </td></tr>    
385: <tr><td>
386:  <form name="form" action="<?php print $self?>" method="post"> 
387: <?php
388:     
if(!isset($_SESSION['user'])){
389: echo 
"username <input name=\"user\" size=\"12\" type=\"text\" maxlength=\"12\" value=\"\">";
390: }else{
391:  echo 
"<span style=\"background-color:yellow;\">Chat name: "
392: echo 
$_SESSION['user'];    
393: echo 
"</span> ";
394:
395:
396:
////////////////////////////////////////////////
397:
if ($captcha) {
398:  function 
rand_pass_string($length) {
399:
$chars 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
400: return 
substr(str_shuffle($chars),0,$length);
401:
402:
$rannum rand_pass_string('9');
403: print 
" <input name=\"m1\" type=\"hidden\" value=\"$rannum\"><span style=\"background-color:lime;\">$rannum</span> ";
404: print 
'<select name="a1">';
405: print 
'<option>Match it</option>';
406:
$i=0;
407: while(
$i 5) {
408:
$rannum1 rand_pass_string('9');
409: print 
"<option>$rannum1</option>";    
410:     
$i++;
411: }
412: print 
"<option>$rannum</option>";    
413:
$c=0;
414: while(
$c 5) {
415:     
$rannum2 rand_pass_string('9');
416: print 
"<option>$rannum2</option>";    
417:     
$c++;
418: }
419: print 
'</select>';
420:
421: }
422:
/////////////////////////////
423:
?>
424:
<textarea style="width:300px;height:100px;" name="box" maxlength="<?php echo $textLength?>"></textarea><br> 
425: <?php
426:        
print "<a onClick=\"addSmiley(':)')\"><img src='images/biggrin.gif'></a> ";
427:        print 
"<a onClick=\"addSmiley(':(')\"><img src='images/sad.gif'></a> ";
428:        print 
"<a onClick=\"addSmiley('[tongue]')\"><img src='images/tongue.gif'></a> ";       
429:        print 
"<a onClick=\"addSmiley(';smirk')\"><img src='images/smirk.gif'></a> ";    
430:        print 
"<a onClick=\"addSmiley(':blush')\"><img src='images/blush.gif'></a> ";
431:        print 
"<a onClick=\"addSmiley(':angry')\"><img src='images/angry.gif'></a> ";
432:        print 
"<a onClick=\"addSmiley(':shocked')\"><img src='images/surprised.gif'></a> ";
433:        print 
"<a onClick=\"addSmiley(':cool')\"><img src='images/cool.gif'></a> ";
434:        print 
"<a onClick=\"addSmiley(':ninja')\"><img src='images/ninja.gif'></a> ";
435:        print 
"<a onClick=\"addSmiley('(heart)')\"><img src='images/heart.gif'></a> ";
436:        print 
"<a onClick=\"addSmiley('(!)')\"><img src='images/exclaim.gif'></a> ";
437:        print 
"<a onClick=\"addSmiley(':[evil]')\"><img src='images/evil.gif'></a> ";
438:        print 
"<a onClick=\"addSmiley(':[bad]')\"><img src='images/naughty.gif'></a> ";             
439:        print 
"<a onClick=\"addSmiley('(?)')\"><img src='images/question.gif'></a><br> ";
440:        print 
"<a onclick=\"addSmiley(':[wink]')\"><img src='images/wink.gif'></a> ";
441:        print 
"<A onclick=\"addSmiley('{clover}')\"><img src='images/clover.gif'></a> ";
442:        print 
"<a onclick=\"addSmiley(':[glasses]')\"><img src='images/glasses.gif'></a> ";
443:        print 
"<a onclick=\"addSmiley(':[barf]')\"><img src='images/barf.gif'></a> ";
444:        print 
"<a onclick=\"addSmiley(':[reallymad]')\"><img src='images/mad.gif'></a>";
445:        print 
"<A onclick=\"addSmiley(':[argue]')\"><img src='images/arguing.gif'></a> ";
446:        print 
"<a onclick=\"addSmiley(':[hitem]')\"><img src='images/hitting.gif'></a> ";
447:        print 
"<a onclick=\"addSmiley(':[eyepoke]')\"><img src='images/eye-poke-smiley-emoticon.gif'></a> ";
448:        print 
"<a onclick=\"addSmiley(':[curse]')\"><img src='images/curse.gif'></a>"
449:        print 
"<a onclick=\"addSmiley(':[eek]')\"><img src='images/eek.gif'></a>";             
450:        print 
"<script language=\"JavaScript\" type=\"text/javascript\">\n";
451:        print 
"function addSmiley(textToAdd)\n";
452:        print 
"{\n";
453:        print 
"document.form.box.value += textToAdd;";
454:        print 
"document.form.box.focus();\n";
455:        print 
"}\n";
456:        print 
"</script><br>";
457:
?>
458:
<input style="text-align:right;" type="submit" name="postit" value="Post it">
459: </form>
460: <br>
461: <form method="link" action="<?php echo $self;?>">
462: <input type="submit" value="Refresh"></form>
463: <?php
464:
if (isset($_GET['admin'])) {
465: echo 
"<form method=\"post\" action=\"shoutbox.php?admin\">";
466: echo 
"password <input name=\"password\" size=\"12\" type=\"password\" maxlength=\"12\" value=\"\">";
467: echo 
'<input type="submit" name="admin" value="login"></form>';    
468: }    
469:
?>
470:

471: </td>
472: </tr>
473: </table>
474: </center>
475: </body>
476: </html>

Please help me I am handicapped and support myself

Donate With PayPal

 

Donate Bitcoin

Please donate and help the handicapped.

19DQT9KTHabkJ7dUCHpzdg5XdSA5mFkCyJ



name:Kaleb Date:08.7.22 @ 06:22am IP:21179..13.1804
Thanks you are cool I sent you 7 cents.


name:Lucretia Date:08.7.22 @ 06:22am IP:081119..341.27
Thanks I sent you 71 cents.


name:Paul Date:08.7.22 @ 06:21am IP:1.2871130.194.
A great help thanks I sent you 35 cents.




Name:
Click Here to Reload

My websites do not use cookies or any google spyware.

 

Quick Support: Make it short.
Email:

Message: