Phenomena Posted March 31, 2007 Share Posted March 31, 2007 So I'm working on my first real php project. I'm still learning but I think im off to good a start. I started to create a simple chat room for learning purpose. (http://modhalotrial.com/php_stuff/chat_room) I just need help with a few things how do i create censored words (using the mysql db with the tables id, before, after) and an auto refresh for the chat because right now new posts only show up when you post or refresh heres my code (remember im still new at this so dont tear it shreds ) <?php require ('config.php'); mysql_connect ($server,$user,$pass) or die("Could not connect to server."); @mysql_select_db ($database); $user = $_POST['user2']; $post = $_POST['text']; $date = date("H:i:s"); $query = "INSERT INTO chat VALUES ('','$post','$date','$user')"; mysql_query($query); ?> <table border="2" cellpadding="5" width="650" height="600"> <tr> <td align="left" ><font size="2"> <?php $query2 = "SELECT * FROM chat"; $result = mysql_query($query2); $num = mysql_numrows($result); $i = 0; while ($i < $num) { $user3=mysql_result($result,$i,user); $chat=mysql_result($result,$i,message); $date=mysql_result($result,$i,date); echo "<b>$user3</b>, <i>$date</i> - $chat<br>"; $i++; } ?> </font> </td> <td align="center" width="175"> Chatters </td> </tr> <td colspan="2" align="center" height="65"> <form action="chat.php" method="post"> User: <input type="text" name="user2" value="<?php if ($user == "") { echo "Anonymous"; } else { echo $user; } ?>" onChange="this.value='Locked text!';" size=12 readonly> Message: <input type="text" name="text" size="50"> <input type="submit" value="Submit"> </form> <?php $n = 0; while ($n < 20) { $emot = "emoticons/$n.gif\""; echo "<img src=\"http://modhalotrial.com/php_stuff/chat_room/$emot>"; $n++; } ?> </td> </table> Link to comment https://forums.phpfreaks.com/topic/45015-php-chat-room-help/ Share on other sites More sharing options...
neel_basu Posted March 31, 2007 Share Posted March 31, 2007 Create A DB Field That Holds the Banned Words And Then First Filter it according to the Fields. Link to comment https://forums.phpfreaks.com/topic/45015-php-chat-room-help/#findComment-218516 Share on other sites More sharing options...
dsaba Posted March 31, 2007 Share Posted March 31, 2007 you can use javascript to auto-refresh and you can also send headers with php to auto-refresh also thats the thing with server side scripting, you have to refresh to get new data however if you use javascript or ajax, you can do some of the refreshign automatically, or stream data in that automatically refreshes without refreshing the actual page ajax and javascript are especially useful for these kinds of projects like chatrooms check this out: http://www.phpfreaks.com/forums/index.php/topic,130749.0.html Link to comment https://forums.phpfreaks.com/topic/45015-php-chat-room-help/#findComment-218554 Share on other sites More sharing options...
neel_basu Posted March 31, 2007 Share Posted March 31, 2007 AJAX != JavaScript But Auto refreshing a frames is not good Link to comment https://forums.phpfreaks.com/topic/45015-php-chat-room-help/#findComment-218555 Share on other sites More sharing options...
Phenomena Posted March 31, 2007 Author Share Posted March 31, 2007 Create A DB Field That Holds the Banned Words And Then First Filter it according to the Fields. I already have that setup, but i cant figure out how to detect if a word posted is in the db. anyways could I also get some C&C on my code, I would like to start coding a site but I want to make sure my code doesn't have too many secruity holes Link to comment https://forums.phpfreaks.com/topic/45015-php-chat-room-help/#findComment-218735 Share on other sites More sharing options...
dsaba Posted April 1, 2007 Share Posted April 1, 2007 query your db for the banned words put the words into an array for ($array as $key => $value) { $matches = preg_match("$value", $text); if ($matches > 0) { do some stuff here, delete the word or reject the whole text } } Link to comment https://forums.phpfreaks.com/topic/45015-php-chat-room-help/#findComment-218941 Share on other sites More sharing options...
neel_basu Posted April 1, 2007 Share Posted April 1, 2007 OK This is the compleate Code. just download it and test it. ------------------------------------------------------- <?php $db_ban = 'db_fld_ban';//Ban Words Field In the Database; $db = 'db'; $tbl = 'table_name'; //Started $conn = mysql_connect("localhost", "root", ""); $test = new browse($db, $tbl, $conn);//db_name, table_name, $conn $test->find($db_ban);//Find Baned Field $result = $test->output();//Array Of banned Words $cnt = true; for($i=0;$i<count($result);$i++){ if(stristr($email, $result[$i])){$cnt = false;} } //Ended if(!$cnt){echo "Contains Banned Words\n";} else{echo "Doesn't Contains Banned Words";} ?> But You have to include_once() 3 files. config.php, db/browse.php, done.php. Please download those files from here.--> http://sourceforge.net/project/showfiles.php?group_id=192566 Remember you have to download the Zigmoyd.php4.mysql.1.0.0.1 ------------------------------------------------------------ Please Respond Is it working or not Link to comment https://forums.phpfreaks.com/topic/45015-php-chat-room-help/#findComment-218999 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.