Index of /simplechat

[ICO]NameLast modifiedSizeDescription

[PARENTDIR]Parent Directory   -  
[DIR]chatex/ 2022-05-15 16:08 -  
[DIR]chatfiles/ 2022-05-15 16:08 -  
[DIR]chattxt/ 2022-05-15 16:08 -  
[TXT]test.html 2022-05-15 16:08 627  

Ajax - PHP Script Chat

Ajax - PHP Chat Script

This is a simple script for Chat, made with PHP and Javascript, using OOP and Ajax technology.


- PHP 5.4+
- Browser with JavaScript enabled.

This Chat script can save chat data in MySQL database or in text files on server, and it uses verry few server's resources.
The chat can be included directly in the html code.
The user can add smiles in chat, and can format the text with Bold, Italic, an Underline., you can test it online to this link: Script Chat Simple
To avoid spam, the user can not add two identically texts one after another, and he can add the next text in chat after 3 seconds.
The nickname, chat room, and the On / Off setting for beep sound are saved in cookies, so, to the next visit they will be read and used from cookie.
The script has been tested successfully on Mozilla Firefox, Internet Explorer, Google Chrome and Opera.
• - This script is free (does not provide support or personal modifications).


1. If you want to store chat data in mysql, open the "setchat.php" file (in the "chatfiles/" folder) and add your data for connecting to MySQL database in the $mysql array (line 8).
2. Set 'mysql' value to the STORAGE constant (line 10).
3. If you want to store chat data in text files on server, let the value 'file' to the STORAGE constant.
4. The script initially contains two chat rooms: English, and Nature. To Add /Modify /Delete chat-room, edit the values in the $chatrooms array.
5. Copy on your server the directories: "chatfiles", "chattxt", and "chatex" (with all their files, in the same directory where you have the file in which you want to include the chat). The "test.html" file is for test.
6. If you want to store chat data in text files, set read-write-execute permissions to the directory "chattxt", CHMOD 0777 (or 0755). In this directory the PHP will save text files with the chat for each chatroom.
7. If you have set to save data in MySQL, access the "create_tables.php" file (in the "chatfiles/" folder) in your server. For example:
8. In the page in which you want to include this chat script, just add the following code: - In the data-style attribute you can add one of these values:

Admin Settings

- In the "setchat.php" file you can change the default settings.
- By default, the script displays the last 40 rows of chat, you can change this number to the line of code: - The script allows users to add links in chat (with attribute rel="nofallow"), but if you want to remove this feature, replace the number 1 with 0, to the line of code:
- To the following line of code you can set a password used when you want to empty chat rooms (replace "adminpass" with the password you want): - To empty chat rooms, access in your browser the file chatfiles/setchat.php with ?mod=admin in URL. For example:
Then select the Chat Room you want to empty, and use the password set to CADMPASS.

- If your web site has a register /login script, and you want than only the logged users to can add texts in chat, set the value of CHATADD to 0 . Then set $_SESSION['username'] with the session your script uses to keep logged users; to the following code, in "setchat.php".
In the directory "chatex/" there are two additional WAV files: "beep2.wav", and "beep3.wav". By default, the script uses "beep1.wav". In case you want to change the audio sound that is played when a new text chat is added in chat room, change in "chatfunctions.js" file (line 14) the value of the variable: - In MySQL database, the script creates a table 'chat_users' that stores online users, and a table "chat_ROOM_NAME" for each chat-room.

The "chattxt/" is the default directory in which the text files with chatrooms are stored, but you can also use sub-folders added in "chattxt/" to store and use the files.
- The sub-folder can be set in the $c_subdir variable (defined in "setchat.php" line 21), default is empty. This is useful if you want to use dinamically directory with chatrooms.
- The script creates automatically the sub-folder in "chattxt/", with the name added in $c_subdir and CHMOD 0755.

The script can create automatically the text files for each chat room (with data in JSON format), but PHP must have writable permissions (CHMOD 0777, or 0755) in the "chattxt" directory (and sub-folders).
The script can be easily changed to be used in other languages, just translate the text in the file "texts.php" (in "chatfiles/" folder).
If you want to modify the colors and design of the chat, edit CSS properties in "chatstyle.css" (or "chatstyle_mini.css", the mini-version), in "chatfiles/" folder.
The file "chatstyle_mini.css" can be used for a smaller graphics version of this chat script (width 245 px). In this version, to save space, the area with online users is not displayed.

With Joy,
Marius /