Online group chat with ipad-like interface

Source: Internet
Author: User
Web Online Group chat (ipad interface) source code all in Ichat.zip compressed package
The main consists of three files:
index.php: Form values get nickname file, pass value tochat.phpFile
Chat . PHP : main file, get index.php value, determine whether to fill in the nickname, Empty is a visitor, this page contains chat input text box, submitted to this page processing, Save chat record in auto-created Chat.txt file, use IFRAME to call view.php to display chat content;
View . PHP : Read the contents of the Chat.txt file by line, reverse output, automatically refresh every 20s interval
To improve: ( I am a novice, is learning )
1. Anti-refresh mechanism
2. Read the content should use Ajax
Demo Address: http://qhbbs.tk/
  1. /* Create a session to determine whether to fill in the nickname, no visitors */
  2. Session_Start ();
  3. if (isset ($_session[' views '))
  4. $_session[' views ']=$_session[' views ']+1;
  5. Else
  6. $_session[' views ']=1;
  7. if ($_session[' views ']==1) $_session[' username ']=$_post[' user '];
  8. if (!$_session[' username ') $_session[' username ']= "tourists";
  9. if ($_post[' user ') $_session[' username ']=$_post[' user '];
  10. $user =$_session[' username '];
  11. $words =$_post[' words '];//chat content Assignment
  12. if (empty ($words)) exit;
  13. Savechat ($words, $_session[' username ');//Save chat content
  14. /* The following is the Save Chat content function */
  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 (' Create chat log file failed, please check if there is 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 (' Write chat record failed. ');
  28. }
  29. Fclose ($FP);
  30. }
  31. ?>
Copy Code
    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 order
    17. foreach ($temp _arr as $value) {
    18. echo "". $value. "". "
      ";
    19. }
    20. ?>
Copy Code
  • 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.