#native_company# #native_desc#
#native_cta#

PHP-Based Chat Room Page 3

By Mike Hall
on July 30, 2000

Now we finally have all we need to write the new file :

<?php 

// Opens file for writing and truncates file length to zero.

$open_file fopen("messages.html""w");

// write file header...

fputs($open_file$header);

// ... new line...

// (stripSlashes because we don't want all

// our escape characters appearing in the

// message file)

fputs($open_filestripslashes($new_message));

// ... old lines ...

fputs($open_file$old_messages);

// ... and footer.

fputs($open_file$footer);

// Close the file when you're done. Don't forget to wash your hands

fclose($open_file);

?>



So we now have a very very basic web chat. Let’s look
at some of the features.
<form action="chat.php3">
Name : <input type="text" name="name"> Color: <input type="text" name="color"><br>
Message : <input type="text" name="message"><br>
<input type="submit" name="Send">
</form>
We’ve added a new input to the form, meaning we get
a nice new variable to play with in the script. We
read the old messages as before, but in compiling
the new one, we use a little more HTML.

<?php 

$new_message "<font color="$color">$name : $message</font><br>n";

?>



And while we’re thinking about it, we’ll add a
few more bells and whistles.

<?php 

$time date("H:i");

$new_message "<font color="$color"><b><i>$name</i></b>".

    
" <font size="1">($time)</font> : $message</font><br>n";

?>