This page shows you how to create your own asynchronous chat client. When you see code below, the pink shows what you should not change, the yellow shows what you may change, and the green shows what you should definitely change.
To enable the girls to create a chat feature on their websites, you will have to set up a Chat client.
What you need:>
This website http://www.php.net provides useful information about PHP and how to install it.
To make your chat client work, you will use a web technology called PHP. PHP is a Hypertext Preprocessor, a server-side program that changes web pages according to instructions in the code before sending them to your browser. This allows your web page to be different each time you refresh, showing what others write into their own chat clients. This is unlike a regular HTML page, which is the same each time you refresh.
You don't need to worry too much about PHP or exactly how it works. Engineers at SRI International have written several functions in PHP for you. Having parts of your code written by other engineers is a common practice in engineering. Yes, you are doing work that engineers do!
To make the PHP work on your page, you need to do two things.
.php
. Our example file is
test_client.php
.<?php require_once('../../async_chat/chat_utils_inc.php'); ?>
The chat client has two main parts: the chat display and the input form.
The chat display itself has two pieces: 1) the chat lines that girls in the class have already said and 2) the "Refresh" button. Clicking the "Refresh" button updates the lines of the chat to show you the most recent things that other girls have said. Remember that an HTML page usually does not change unless you click something, such as "Reload" or a new link. |
Example of Chat Display Melissa: hi Zaz: hello, melissa Melissa: my name is blue! Zaz: mine was red but now it is purple Melissa: i am still blue |
To make the chat lines and the "Refresh" button work, they will
have to be inside an html form. This form points to your own chat
page (ours is called test_client.php ). The name of your
"Refresh" button should be "refresh". Finally, to make
your chat lines display, you will call a PHP function called
print_chat . You will need to tell this function how many lines
you want to show at once, which must be at least 1. Our example uses 5.
|
Code for Chat Display
<form method="post" action="test_client.php">
|
The input form has four parts:
|
Example of Input Form |
All of the parts listed above are also going to be in a form that is just like the one you made for chat display. The PHP functions you see in the name and color text fields let the page remember the name and color you entered last time. |
Code for Input Form
<form method="post" action="test_client.php">
|
There are a few special rules you need to remember or your chat will not work:
name="
. (For example, name="Say"
).
As long as you follow the rules and use the pieces of code that appear above,
you can make your page look however you like. Just be sure to not change anything
pink and to read the instructions carefully. For example,
you can change the background of your page to be a different color by changing
<body>
to <body bgcolor="lightblue">
.