Hi, I am thinking of developing a chat machine in php. Can anyone help me with some sample code, please? Thanks
i suggest you use ajax.. with a time out in the ajax function visit this url http://www.w3schools.com/ajax/ajax_example_suggest.asp in the event, instead of onKeyUp, make this a onSubmit or onClick then set the timeout inside the js function t=setTimeout(ajaxfunction(),1000); this will refresh the container every 1 sec
so, here is the logic: The page will contain like 2 DIVs. All of the chat messages will be saved at the first DIV. The second DIV will contain the chat form, where we can submit a message. You will need AJAX to do the message fetching in the background, and set a timeout (like 1000ms) to the javascript function (which do the fetching) to make it real-time. The javascript codes will fetch the messages from a PHP code that fetches the messages from the database (or maybe directly to the Text file if you're using flat file database), and the javascript will routinely write the returned data from the PHP to the DIV (ie. 1000ms each refresh).