Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallYou can build a basic chat room with a small HTML page, jQuery AJAX polling, a PHP endpoint, and a writable text file—no database required. The design is useful for learning how browser requests and server-side storage fit together, but it is a demo rather than a production-ready chat service.
The example below follows Chris Coyier’s CSS-Tricks tutorial, published May 5, 2015. To run it, you need a PHP-capable web server and permission for PHP to write to the chat file; opening the files directly from your computer will not work.
How the chat room works
The implementation separates responsibilities between the browser and the server. The page contains a name area, a chat display, and a message textarea. The textarea limits each message to 100 characters. jQuery sends AJAX POST requests to a PHP script, which reads or updates a plain-text file named chat.txt.
- Browser: asks for a nickname, sends messages, requests updates, displays returned messages, and scrolls the chat view.
- PHP endpoint: handles the requested operation, reads or appends chat data, and returns a JSON response.
- Text file: stores chat lines without requiring a database.
In the tutorial, the JavaScript Chat function provides getState, update, and send operations. Each AJAX request posts to process.php with a function value identifying the operation. PHP switches on that value and encodes the response with json_encode.
#1 Best Overall
How polling and message state work
The page calls chat.update() once per second. This is polling: the browser repeatedly asks the server whether anything has changed. It is not a WebSocket or a persistent push connection, so each check is a separate request.
- Get the current state: the client calls
getState, and PHP counts the lines inchat.txt. The browser records that count as its known state. - Request later lines: on an update, the client sends its known line count. PHP returns only lines after that position rather than sending the complete chat history every time.
- Display new messages: the browser adds the returned messages to the chat area and updates its state so the next request starts after the lines it has received.
- Send a message: the browser posts the nickname and message with the
sendoperation. PHP processes the input and appends the formatted result to the file.
This line-count approach keeps the example compact. It also means the stored file is the state source for the chat; the tutorial does not describe a separate user, room, or message database.
Rank #2
What the PHP example does with input
For a submitted nickname and message, the tutorial’s PHP code strips tags and applies htmlentities before writing the formatted line. It also recognizes URL-shaped text and turns it into a link. In the browser, the message field has a 100-character limit.
These are useful teaching examples of input handling, not a complete security review. The code dates from 2015, so do not treat its escaping and client-side limit as sufficient protection for a public service. Client-side limits can be bypassed, and output handling should be reviewed for every context in which data is rendered. The tutorial also does not establish a complete approach to CSRF protection, user sessions, abuse controls, or safe concurrent file writes.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Scan for outdated or missing drivers - takes under a minute3Repair Windows errors before they cause bigger problemsSet it up on a PHP-capable server
- Place the page,
process.php, andchat.txtwhere your PHP-capable web server can serve and execute them. - Make sure the server process can write to
chat.txt. The exact permission method depends on the server and hosting configuration; avoid making the file broadly writable when a narrower permission will work. - Load the page through the server’s web address and test sending a message from the browser. Do not open the HTML file directly from disk: in that case, PHP will not run as the page’s backend.
- If requests fail, check that PHP is enabled for the site, that the endpoint path is correct, and that the server can write to the chat file. Inspect the browser’s network and console panels and the server’s PHP error log for the actual failure.
What this demo does not provide
The original tutorial explicitly presents the project as a small chat program, not a full-featured replacement for IRC. It does not provide kicking or banning, a current-member list, or protection against two users choosing the same name. It also does not establish private rooms, authentication, moderation workflows, or a scalable deployment design.
Its dependency context is dated as well: the page loads jQuery 1.4.4 from Google’s CDN. Before reusing the code, review whether that legacy dependency is appropriate for your environment and update the client-side code and security design as needed. The tutorial’s one-second polling cadence is an implementation setting, not evidence of a measured performance level or a guarantee that it will suit many simultaneous users.
Rank #4
When to use this approach—and when to choose another
Use the text-file version as a compact way to learn the request cycle: the browser submits data, PHP processes it, and the client retrieves new state. If you need a maintained service for real users, compare options against the features and operational model you actually need. A SitePoint roundup, published in 2012 and updated February 12, 2024, discusses alternatives including ArrowChat (PHP/MySQL) and Candy (JavaScript/XMPP): SitePoint’s chat application roundup.
- Storage: flat file versus a database or another persistence system.
- Transport: periodic polling versus a push-based connection.
- User features: authentication, presence, private rooms, and moderation.
- Operations: installation effort, expected traffic, logging, and how the system handles simultaneous writes.
The right choice depends on which of those requirements matter; the existence of an alternative in a roundup does not by itself establish its current support status or suitability.
Recommended Free Tools
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

