Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 915717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:56:06+00:00 2026-05-15T17:56:06+00:00

I’ve made a chat application for a website. Everything is working fine, however, I

  • 0

I’ve made a chat application for a website. Everything is working fine, however, I am trying to make a situation where when the user clicks ‘logout’, the chat box system will show to other users that the specific user has indeed logged out of the room, and then it will proceed to clear all old messages on the user’s screen who has logged out, in case the user comes back in that same room they won’t be able to see any of the old conversations they had.
The file which saves all the messages from the chat box is ‘log.html’. For some reason, my code was partially working fine before, i.e. the log.html was being truncated when the user clicked logout, but I can never get that log.html file to write that the user has indeed logged out, now both of them don’t work. Can someone look at my code and let me know if I’m even doing it right? By the way, the codes might not even contain the actual problem, but then again, it might, so feel free to ask if you need more information.

This code piece comes from group2.php, where the chatbox is stored:

session_start();  

if(isset($_GET['logout'])){     

//Simple exit message for chat log
$fp = fopen("log.html", 'a');
fwrite($fp, "<div class='msgln'><i>User ". $_SESSION['name'] ." has left the chat session.</i><br></div>");
fclose($fp);

    //Truncate the log file
     $fp = fopen("log.html", 'w');
     fclose($fp);

    session_destroy();
header("Location: main.php"); //Redirect the user        
                        }  

This is also some code from group2.php that might be of some help:

<div id="menu">
    <p class="welcome">Welcome, <b><?php echo $_SESSION['name']; ?></b></p>
    <p class="logout" name="logout" ><a id="exit" name="logout" href="#">Exit Group</a></p>
    <div style="clear:both"></div>
</div>  

I was also thinking, could it be, I need to echo out that the user has left, and clear out the log.html file, within this code instead??

//If user wants to end session
    $("#exit").click(function(){
        var exit = confirm("Are you sure you want to end the session?");
        if(exit==true){window.location = 'main.php?logout=true';}
    });  
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T17:56:06+00:00Added an answer on May 15, 2026 at 5:56 pm

    If I may ask, why were you clearing the file: $fp = fopen(“log.html”, ‘w’); after writing to it a few lines before?

    I think a better solution would be:

    $fp = fopen("log.html", 'w');
    fwrite($fp, "<div class='msgln'><i>User ". $_SESSION['name'] ." has left the chat session.</i><br></div>");
    fclose($fp);
    

    Also, I think that you might have to write something to the file for the truncate to go into effect (per say). So, if you wanted to keep the current code, add a fwrite($fp, “”); after the $fp = fopen(“log.html”, ‘w’);

    Hope that helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.