Results 1 to 10 of 10

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

  1. #1
    pipesportugal's Avatar
    pipesportugal is offline Second Lieutenant
    Join Date
    Jul 2007
    Location
    Oporto - Portugal
    Posts
    129

    Default 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

  2. #2
    Watdaflip's Avatar
    Watdaflip is offline Major General
    Join Date
    Sep 2005
    Location
    Cincinnati, Ohio
    Posts
    2,119

    Default 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

  3. #3
    pipesportugal's Avatar
    pipesportugal is offline Second Lieutenant
    Join Date
    Jul 2007
    Location
    Oporto - Portugal
    Posts
    129

    Default 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

  4. #4
    pipesportugal's Avatar
    pipesportugal is offline Second Lieutenant
    Join Date
    Jul 2007
    Location
    Oporto - Portugal
    Posts
    129

    Default 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

  5. #5
    Watdaflip's Avatar
    Watdaflip is offline Major General
    Join Date
    Sep 2005
    Location
    Cincinnati, Ohio
    Posts
    2,119

    Default 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

  6. #6
    pipesportugal's Avatar
    pipesportugal is offline Second Lieutenant
    Join Date
    Jul 2007
    Location
    Oporto - Portugal
    Posts
    129

    Default 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

  7. #7
    pipesportugal's Avatar
    pipesportugal is offline Second Lieutenant
    Join Date
    Jul 2007
    Location
    Oporto - Portugal
    Posts
    129

    Default 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

  8. #8
    navaldesign's Avatar
    navaldesign is offline General & Forum Moderator
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    12,115

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

    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!


  9. #9
    pipesportugal's Avatar
    pipesportugal is offline Second Lieutenant
    Join Date
    Jul 2007
    Location
    Oporto - Portugal
    Posts
    129

    Default 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


  10. #10
    navaldesign's Avatar
    navaldesign is offline General & Forum Moderator
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    12,115

    Default 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!


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49