Announcement

Collapse
No announcement yet.

Clearing Chatroom after exiting it

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Clearing Chatroom after exiting it

    I have this chatroom on this website. The problem I'm having is. When you finish a conversation and leave the chat room. it doesn't clear the conversation. When I go back in later. everything is still there. Is there a way to get it to clear on it''s own after leaving the chat?

    http://www.empoweredgolfersmanitoba.ca/Chatroom.php

  • #2
    Hi there conquer,

    it was pointed out in this thread...
    Chat room text will not clear
    "We cannot help you with what your code is doing without having all the code needed to reproduce the problem."
    I, of course, would have replied in a similar manner.



    ~ the original bald headed old fart ~

    Comment


    • #3
      Okay, I'm not much on PHP, but it seems to me that you're loading the log.html page. Is there a way you could load a blank page each time the chat is opened?
      Cat-herder Extraordinaire

      Comment


      • #4
        I hope this helps .


        PHP Code:
        <?php
          $pageTitle 
        " Products";
          include(
        'inc/header.php');

        ?>
         <div class="container bgWhite">
              <div class="row">
                    <div  style="padding-top: 15px;">
                        <div id="myCarousel" class="carousel slide" data-ride="carousel">
                            <!-- Indicators -->
                            <ol class="carousel-indicators">
                                <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
                                <li data-target="#myCarousel" data-slide-to="1"></li>
                                <li data-target="#myCarousel" data-slide-to="2"></li>
                            </ol>

                            <!-- Wrapper for slides -->
                             <div class="carousel-inner" role="listbox">
                                <div class="item active">
                                    <img src="img/AdobeStock_83234383.jpeg" alt="" width="1920" height="546">
                                </div>
                                <div class="item">
                                  <img src="img/AdobeStock_110313737.jpg" alt="" width="1920" height="546">
                                </div>
                                <div class="item">
                                 <img src="img/AdobeStock_72595945.jpeg" alt="" width="1920" height="546">
                                </div>
                            </div>

                            <!-- Left and right controls -->
                            <a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
                                <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
                                <span class="sr-only">Previous</span>
                            </a>
                            <a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
                                <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
                                <span class="sr-only">Next</span></a>
                                </div>
                        </div>
                    </div>
                </div>
                <p></p>
                <div class="container bgWhite">
                 <h2>Chatroom</h2>

             <p>  </p>
            </div>
        </div>
        <p></p>



                <p></p>
                <div class="container bgWhite">
                &nbsp;
                <iframe src="chatroom/index.php" width="100%" height="500px" frameborder="0"></iframe>


          </div>

        </div>


        <?php include('inc/footer.php'); ?>


        PHP Code:
        <?php
        session_start 
        ();
        function 
        loginForm() {
            echo 
        '
            <div id="loginform">
            <form action="index.php" method="post">
                <p>Please enter your name to continue:</p>
                <label for="name">Name:</label>
                <input type="text" name="name" id="name" />
                <input type="submit" name="enter" id="enter" value="Enter" />
            </form>
            </div>
            '
        ;
        }

        if (isset ( 
        $_POST ['enter'] )) {
            if (
        $_POST ['name'] != "") {
                
        $_SESSION ['name'] = stripslashes htmlspecialchars $_POST ['name'] ) );
                
        $fp fopen "log.html"'a' );
                
        fwrite $fp"<div class='msgln'><i>User " $_SESSION ['name'] . " has joined the chat session.</i><br></div>" );
                
        fclose $fp );
            } else {
                echo 
        '<span class="error">Please type in a name</span>';
            }
        }

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

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

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

        ?>
        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
        <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
        <style>
        body {
            font: 20px arial;
            color: #222;
            text-align: center;
            padding: 35px;
        }

        form,p,span {
            margin: 0;
            padding: 0;
        }

        input {
            font: 20px arial;
        }

        a {
            color: #F4080F;
            text-decoration: none;
        }

        a:hover {
            text-decoration: underline;
        }

        #wrapper,#loginform {
            margin: 0 auto;
            padding-bottom: 25px;
            background: #EBF4FB;
            width: 504px;
            border: 2px solid #000000;
        }

        #loginform {
            padding-top: 18px;
        }

        #loginform p {
            margin: 5px;
        }

        #chatbox {
            text-align: left;
            margin: 0 auto;
            margin-bottom: 25px;
            padding: 10px;
            background: #fff;
            height: 230px;
            width: 430px;
            border: 2px solid #000000;
            overflow: auto;
        }

        #usermsg {
            height:50px;
            width: 395px;
            border: 2px solid #000000;
        }

        #submit {
            width: 60px;
        }

        .error {
            color: #ff0000;
        }

        #menu {
            padding: 12.5px 25px 12.5px 25px;
        }

        .welcome {
            float: left;
        }

        .logout {
            float: right;
        }

        .msgln {
            margin: 0 0 2px 0;
        }
        </style>
        <title>Chat - Customer Module</title>
        </head>
        <body>
            <?php
            
        if (! isset ( $_SESSION ['name'] )) {
                
        loginForm ();
            } else {
                
        ?>
        <div id="wrapper">
                <div id="menu">
                    <p class="welcome">
                        Welcome, <b><?php echo $_SESSION['name']; ?></b>
                    </p>
                    <p class="logout">
                        <a id="exit" href="#">Exit Chat</a>
                    </p>
                    <div style="clear: both"></div>
                </div>
                <div id="chatbox"><?php
                
        if (file_exists "log.html" ) && filesize "log.html" ) > 0) {
                    
        $handle fopen "log.html""r" );
                    
        $contents fread $handlefilesize "log.html" ) );
                    
        fclose $handle );

                    echo 
        $contents;
                }
                
        ?></div>

                <form name="message" action="">
                    <input name="usermsg" type="text" id="usermsg" size="63" /> <input
                        name="submitmsg" type="submit" id="submitmsg" value="Send" />
                </form>
            </div>
            <script type="text/javascript"
                src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
            <script type="text/javascript">
        // jQuery Document
        $(document).ready(function(){
        });

        //jQuery Document
        $(document).ready(function(){
            //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 = 'index.php?logout=true';}
            });
        });

        //If user submits the form
        $("#submitmsg").click(function(){
                var clientmsg = $("#usermsg").val();
                $.post("post.php", {text: clientmsg});
                $("#usermsg").attr("value", "");
                loadLog;
            return false;
        });

        function loadLog(){
            var oldscrollHeight = $("#chatbox").attr("scrollHeight") - 20; //Scroll height before the request
            $.ajax({
                url: "log.html",
                cache: false,
                success: function(html){
                    $("#chatbox").html(html); //Insert chat log into the #chatbox div

                    //Auto-scroll
                    var newscrollHeight = $("#chatbox").attr("scrollHeight") - 20; //Scroll height after the request
                    if(newscrollHeight > oldscrollHeight){
                        $("#chatbox").animate({ scrollTop: newscrollHeight }, 'normal'); //Autoscroll to bottom of div
                    }
                  },
            });
        }

        setInterval (loadLog, 2500);
        </script>
        <?php
            
        }
            
        ?>
            <script type="text/javascript"
                src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
            <script type="text/javascript">
        </script>
        </body>
        </html>
        PHP Code:
        <?php
        session_start
        ();
        if(isset(
        $_SESSION['name'])){
            
        $text $_POST['text'];

            
        $fp fopen("log.html"'a');
            
        fwrite($fp"<div class='msgln'>(".date("g:i A").") <b>".$_SESSION['name']."</b>: ".stripslashes(htmlspecialchars($text))."<br></div>");
            
        fclose($fp);
        }
        ?>

        HTML Code:
        <div class='msgln'><i>User Test has joined the chat session.</i><br></div><div class='msgln'><i>User Test has left the chat session.</i><br></div><div class='msgln'><i>User test has joined the chat session.</i><br></div><div class='msgln'><i>User test has left the chat session.</i><br></div>

        Comment


        • #5
          Hi there conquer,

          actually, it would be a lot easier if instead of posting snippets of code, which go
          I know not where, you just put the whole site in a zip file and attached it to a post.

          You can omit images though, to make the zip file lot smaller.
          Last edited by coothead; 10-18-2016, 02:53 PM.


          ~ the original bald headed old fart ~

          Comment


          • #6
            I tryed sending. I was told to big of file.

            Comment


            • #7
              Hi there conquer,

              upload it to your site, give me a link to it in a post or a PM, if you prefer.

              I will let you know when I have it and you can then remove it from your site.


              ~ the original bald headed old fart ~

              Comment


              • #8
                Hi there conquer,

                whilst waiting for your reply, I took the liberty of compressing the
                four images on you site from 2.66MB to a measly 332KB.

                This will give you great savings in bandwidth and load time.

                Check out the attachment.

                Attached Files


                ~ the original bald headed old fart ~

                Comment


                • #9
                  got it, thanks man.

                  Comment


                  • #10
                    Hi there conquer,

                    You will need to change this...

                    Code:
                    
                    <div class="item active">
                     <img src="img/AdobeStock_83234383.jpeg" alt="" width="1920" height="546">
                    </div>
                    <div class="item">
                     <img src="img/AdobeStock_110313737.jpg" alt="" width="1920" height="546">
                    </div>
                    <div class="item">
                     <img src="img/AdobeStock_72595945.jpeg" alt="" width="1920" height="546">
                    </div>
                    ...to this...
                    Code:
                    
                    <div class="item active">
                     <img src="img/AdobeStock_83234383.jpg" alt="" width="1920" height="546">
                    </div>
                    <div class="item">
                     <img src="img/AdobeStock_110313737.jpg" alt="" width="1920" height="546">
                    </div>
                    <div class="item">
                     <img src="img/AdobeStock_72595945.jpg" alt="" width="1920" height="546">
                    </div>


                    ~ the original bald headed old fart ~

                    Comment


                    • #11
                      thanks. haveing computer problems were loading it up now.

                      Comment


                      • #12
                        Hi there conquer,

                        I can clear the contents of the chat room when clicking "Exit Chat", no problem.

                        Of course, this option will also be available to other occupants of the chat room.

                        This means that a visitor could enter the room, leave a message, click "Exit Chat"
                        and you would be totally unaware of the message.

                        I await your comments, with interest.



                        ~ the original bald headed old fart ~

                        Comment


                        • #13
                          This is what I am seeing.

                          Attached Files

                          Comment


                          • #14

                            Have you not read post #12 yet?


                            ~ the original bald headed old fart ~

                            Comment


                            • #15
                              Yes I read #12 and I agree with you. But thats not whats happening here. I go to the website and then chatroom and I see the old stuff from days ago. I exit and go back later and still same stuff. I'm puzzled.

                              Comment

                              Working...
                              X