Logout a user from reserved area that exits through the X(close window)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • pipesportugal
    Second Lieutenant

    • Jul 2007
    • 130

    Logout a user from reserved area that exits through the X(close window)

    Hello dear colleagues from the VH forum,

    In one of my last threads I received some good ideas about how to control which users were still logged into the reserved area of my webpage.

    Now I am puting a 1 on a field when they login and I have also a lastclick time field on the database when they jump from one page to other through the use of my links.

    But when they click on the X(close window) of the browser, is there a way of logging them out in that same instant ? Without being obliged to make comparisons everytime between lastclick and current time?

    I have been in a website (no publicity...) instantchess.com that when You click on the X to close window Your receive a window.alert from the system saying goodbye or something like that.
    This means that there must be a way of controling if that X was clicked and if there is a window with a message, of course that there could be a clean logout written on the mySQL database.

    Can someone teach me how we can control this event ?

    Thanks in advance for all the answers,
    pipesportugal
  • Watdaflip
    Major General

    • Sep 2005
    • 2116

    #2
    Re: Logout a user from reserved area that exits through the X(close window)

    Most likely their either are using a cookie as well that is set to expire when the window closes, or they are using AJAX to execute a logout script when they click the x.

    If want to do a cookie you need to make sure you have a session id set for users when they login. This is stored in both the database and the cookie, and compared along with the username and password to verify they are logged in. (Either set the cookie to 0, or omit it and it will expire when the browser closes).

    For an AJAX method I can't help you with that. I haven't had the time to learn enough to explain it. Basically it is some javascript code that will allow you to execute a php script and return values from it without the page reloading.

    I hope this helps.

    Register/Login Script
    Do you use a Password Protected Directory? Need a way to allow users to make their own account, try my .htaccess Login Script

    Comment

    • pipesportugal
      Second Lieutenant

      • Jul 2007
      • 130

      #3
      Re: Logout a user from reserved area that exits through the X(close window)

      ok thanks watdaflip,

      I' ll ask for help at a java/ajax forum.

      If I find the solution it will be posted here.

      pipesportugal

      Comment

      • pipesportugal
        Second Lieutenant

        • Jul 2007
        • 130

        #4
        Re: Logout a user from reserved area that exits through the X(close window)

        Hello dear colleagues from the VH forum,

        I have posted some threads at some ajax/java forums about this subject but no one has replied yet.

        So I would like to try to do the following: (as suggested by navaldesign...)

        I have 2 fields on the table "users".
        One is called "lastclick" and is a datetime type.
        Other is a "logged_in_out" and is a tinyint(2) just to hold a 0 or 1.

        Everytime the user clicks inside the reserved area to navigate there I save in the "lastclick" field the datetime this has ocurred.

        When he enters the reserved area I put a 1 on "the logged_in_out" field, this way the systems knows that he is online.

        Also when he gets out through the "close session" button I do the opposite which is: write a 0 at the "logged_in_out" field and write the present datetime at the "lastclick" field.

        As sometimes the user exits the site at the X(close window) and I don't have a clean logout, so a friend recomended me to make a trigger at the mySQL database that would read the "users" table and check all the users that have the "logged_in_out" field with the value 1, and to compare the "lastclick" field value with the present datetime and if the difference is greater that 5 minutes to place a 0 at the "logged_in_out" field.

        This would make a clean logout of the user.

        Does anyone know how can I create this trigger at mySQL ?

        Thanks in advance for all the help,

        pipesportugal

        Comment

        • Watdaflip
          Major General

          • Sep 2005
          • 2116

          #5
          Re: Logout a user from reserved area that exits through the X(close window)

          A cron job will allow you to execute a script/file every certain period of time you specify. For instance you can have a cron job set to execute a php script every 30 minutes which will check if the users login has expired and they are still marked as logged in. There is a page in cPanel to create the cron job

          Register/Login Script
          Do you use a Password Protected Directory? Need a way to allow users to make their own account, try my .htaccess Login Script

          Comment

          • pipesportugal
            Second Lieutenant

            • Jul 2007
            • 130

            #6
            Re: Logout a user from reserved area that exits through the X(close window)

            Hi watdaflip,

            When I have gone to cpanel to create the cron job there were some red letters (imagine must be an error/warning message as follows:



            - I have chosen the "Standard" button,
            - The next screen shows my options:




            I created a php program called testhora.php like this:


            include("include/dbconnect.php");

            $now_less_fifteen.......(makes some calculations...)

            mysql_query("UPDATE tabela_users SET logg_users=0 WHERE logg_users = 1 and clik_users < '$now_less_fifteen'");

            The variable $now_less_fifteen already has inside the present datetime less fifteen minutes.

            Is this the way to create the cron job ?

            Thank You so much for all the help,
            pipesportugal

            Comment

            • pipesportugal
              Second Lieutenant

              • Jul 2007
              • 130

              #7
              Re: Logout a user from reserved area that exits through the X(close window)

              Hello All,

              To close this thread, You should put on the command textbox on the previous thread the following line:

              cd '/home/YOURUSERNAME/public_html/'; php -q 'YOURPROGRAMNAME.php';

              pipesportugal

              Comment

              • navaldesign
                General & Forum Moderator

                • Oct 2005
                • 12080

                #8
                Re: Logout a user from reserved area that exits through the X(close window)

                Hi,



                post #5 and other similar.
                Navaldesign
                Logger Lite: Low Cost, Customizable, multifeatured Login script
                Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
                DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
                Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

                Comment

                • pipesportugal
                  Second Lieutenant

                  • Jul 2007
                  • 130

                  #9
                  Re: Logout a user from reserved area that exits through the X(close window)

                  Hello navaldesign,

                  I never meant to to take out the credit from You or previous thread.

                  If I gave You that idea, I am sorry.

                  And to make it public, it is true that I myself also used the above naval thread to solve my problem.

                  Credit's are done, let's get into the subject.

                  I found out in another forum the following JAVA event.
                  <html>
                  <body onunload="alert('The Window was closed at the X - closewindow button')">
                  </body>
                  </html>

                  With this event You can "control" if the user has closed the present window.

                  Hope this helps others,
                  pipesportugal

                  Comment

                  • navaldesign
                    General & Forum Moderator

                    • Oct 2005
                    • 12080

                    #10
                    Re: Logout a user from reserved area that exits through the X(close window)

                    Hi pipes,

                    this was not meant as a regret abot credits, it was only meant as "solutions most probably are already on the forum, search for them".

                    regarding the "onunload" event: you should use a HTTPRequest (Ajax) to triger a php script that will update your database (or set / unset a cookie) when a user closes the brower using the X or a close window command.
                    Navaldesign
                    Logger Lite: Low Cost, Customizable, multifeatured Login script
                    Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
                    DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
                    Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

                    Comment

                    Working...
                    X