Jump to content

PHP chat room help


Phenomena

Recommended Posts

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 :P)

<?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

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

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 :P

Link to comment
https://forums.phpfreaks.com/topic/45015-php-chat-room-help/#findComment-218735
Share on other sites

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.