Web Hosting Vodahost    

Home Take The Royal Tour! Order Now Features Prices
Go Back   Web Hosting > VodaHost Web Hosting Support > mySQL & PHP

Notices

mySQL & PHP Discussions, information and help with mySQL and PHP.

Reply
 
LinkBack Thread Tools
  #1  
Old 12-12-2007, 01:24 AM
pipesportugal's Avatar
Second Lieutenant
 
Join Date: Jul 2007
Location: Oporto - Portugal
Posts: 101
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #2  
Old 12-13-2007, 06:25 AM
Watdaflip's Avatar
Brigadier General
 
Join Date: Sep 2005
Location: Cincinnati, Ohio
Posts: 1,638
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old 12-13-2007, 11:10 AM
pipesportugal's Avatar
Second Lieutenant
 
Join Date: Jul 2007
Location: Oporto - Portugal
Posts: 101
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old 12-17-2007, 02:35 AM
pipesportugal's Avatar
Second Lieutenant
 
Join Date: Jul 2007
Location: Oporto - Portugal
Posts: 101
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old 12-17-2007, 08:35 PM
Watdaflip's Avatar
Brigadier General
 
Join Date: Sep 2005
Location: Cincinnati, Ohio
Posts: 1,638
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old 12-19-2007, 01:56 AM
pipesportugal's Avatar
Second Lieutenant
 
Join Date: Jul 2007
Location: Oporto - Portugal
Posts: 101
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
Old 12-20-2007, 03:54 PM
pipesportugal's Avatar
Second Lieutenant
 
Join Date: Jul 2007
Location: Oporto - Portugal
Posts: 101
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8  
Old 12-20-2007, 04:01 PM
navaldesign's Avatar
General & Forum Moderator
 
Join Date: Oct 2005
Location: Italy
Posts: 9,346
Default Re: Logout a user from reserved area that exits through the X(close window)

Hi,

http://www.vodahost.com/vodatalk/cpa...ron#post198571

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!

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #9  
Old 12-23-2007, 06:37 PM
pipesportugal's Avatar
Second Lieutenant
 
Join Date: Jul 2007
Location: Oporto - Portugal
Posts: 101
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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #10  
Old 01-03-2008, 09:24 PM
navaldesign's Avatar
General & Forum Moderator
 
Join Date: Oct 2005
Location: Italy
Posts: 9,346
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!

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT +1. The time now is 03:50 AM.


Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC7
2005-2009 VodaHost Web Hosting Your Perfect Web Host - All Rights Reserved

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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176