Online chat on an iPad-like interface

Source: Internet
Author: User
Online chat on an iPad-like interface
The source code of the web online chat (iPad interface) is included in the ichat.zip package.
It consists of three files:
Index. php: obtain the nickname file from the form value and pass the value to the chat. php file;
Chat. php: In the chat file, use iframe to call view. php to display the chat content;
View. php: reads the content of the chat.txt file by row and outputs it in reverse order. the content is automatically refreshed every 20 seconds.
To be improved: (new to me, learning)
1. anti-refresh mechanism
2. ajax should be used to read the content
Demo address: http://qhbbs.tk/

  1. /* Create a session and determine whether to enter a nickname. if not, it is a visitor */
  2. Session_start ();
  3. If (isset ($ _ SESSION ['View'])
  4. $ _ SESSION ['View'] = $ _ SESSION ['View'] + 1;
  5. Else
  6. $ _ SESSION ['View'] = 1;
  7. If ($ _ SESSION ['View'] = 1) $ _ SESSION ['username'] = $ _ POST ['user'];
  8. If (! $ _ SESSION ['username']) $ _ SESSION ['username'] = "tourist ";
  9. If ($ _ POST ['user']) $ _ SESSION ['username'] = $ _ POST ['user'];
  10. $ User = $ _ SESSION ['username'];
  11. $ Words = $ _ POST ['word']; // chat content assignment
  12. If (empty ($ words) exit;
  13. Savechat ($ words, $ _ SESSION ['username']); // Save the chat content
  14. /* The following is the function for saving chat content */
  15. Function savechat ($ msg, $ user)
  16. {
  17. $ Date = date ('H: I: S', time ());
  18. $ DOCUMENT_ROOT = $ _ SERVER ['document _ root'];
  19. If (! $ Fp = fopen ("$ DOCUMENT_ROOT/chat.txt", 'A + ')){
  20. Die ('failed to create the chat record file. Please check if you have the permission .');
  21. }
  22. $ Msg = htmlspecialchars ($ msg );
  23. $ Msg = preg_replace ('/([httpftp: \ //]) * ([a-zA-]) + \. ([a-zA-Z0-9 _-]) + \. ([a-zA-Z0-9 _-]) + (a-zA-Z0-9 _) */',' \ 0', $ msg );
  24. $ Msg = preg_replace ('/([a-zA-Z0-9 _ \.]) + @ ([a-zA-Z0-9-]) + \. ([a-zA-Z0-9-] {2, 4}) +/',' \ 0', $ msg );
  25. $ Msg = '['. $ date. ']'. "\ t". $ user. ":". $ msg. "\ n ";
  26. If (! Fwrite ($ fp, $ msg )){
  27. Die ('failed to write the chat record .');
  28. }
  29. Fclose ($ fp );
  30. }
  31. ?>

  1. $ DOCUMENT_ROOT = $ _ SERVER ['document _ root'];
  2. $ Fp = fopen ("$ DOCUMENT_ROOT/chat.txt", 'A + ');
  3. If (! $ Fp ){
  4. Echo"

    Didn't write chat log in chat.txt. Please try say again.

    ";
  5. Exit;
  6. }
  7. $ Handle = $ fp;
  8. $ Temp_arr = array ();
  9. Do
  10. {
  11. $ File = fgets ($ handle, 1024 );
  12. $ Temp_arr [] = $ file;
  13. }
  14. While (! Feof ($ handle ));
  15. Fclose ($ handle );
  16. Krsort ($ temp_arr); // reverse
  17. Foreach ($ temp_arr as $ value ){
  18. Echo "". $ value .""."
    ";
  19. }
  20. ?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.