Current location: Hot Scripts Forums » Programming Languages » Perl » Lost Control


Lost Control

Reply
  #1 (permalink)  
Old 12-17-03, 11:06 PM
DAL's Avatar
DAL DAL is offline
Code Master
 
Join Date: Jun 2003
Location: North East England/UK
Posts: 874
Thanks: 0
Thanked 0 Times in 0 Posts
Lost Control

I have lost control when it comes to logging out of my site. If a user selects logout then it take them to a page that asks to close the windows. This is fine, as this page in the background actually gives the user profile a recorded logout time. But the place where I have lost control is if they just close the window on IE. This wouldnt call the procedure to write a logout time. Is their any way that I can action a pl script at the time the user clicks "X" to close the IE browser window?


Also Going back to user login. How do I test if users are activly logged in? Im using env var and If I test say;

$Userid = $ENV{'REMOTE_USER'};

if ($Userid eq "Dave"){$Daveloggedin = "True"};
if ($Userid eq "John"){$Daveloggedin = "True"};

because the $ENV{'REMOTE_USER'}; is only local isnt it? Or does it pick up from the server and can have more than just my login at the time?
__________________
"once upon a midnight dreary, while i pron surfed, weak and weary, over many a strange and spurious site of 'hot xxx galore'. While i clicked my fav'rite bookmark, suddenly there came a warning, and my heart was filled with mourning, mourning for my dear amour," 'Tis not possible!", i muttered, "give me back my free hardcore!" quoth the server, 404."
Reply With Quote
  #2 (permalink)  
Old 12-18-03, 09:43 AM
Chas Chas is offline
Coding Addict
 
Join Date: Oct 2003
Location: California
Posts: 359
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by DAL
I have lost control when it comes to logging out of my site. If a user selects logout then it take them to a page that asks to close the windows. This is fine, as this page in the background actually gives the user profile a recorded logout time. But the place where I have lost control is if they just close the window on IE. This wouldnt call the procedure to write a logout time. Is their any way that I can action a pl script at the time the user clicks "X" to close the IE browser window?
Not really. The only thing I can suggest is that you log the time of every request made by the user. You can then use the last time as the logout time. But there is nothing you can do to check if a user just hits the X to close the window.

Quote:
Originally Posted by DAL
Also Going back to user login. How do I test if users are activly logged in? Im using env var and If I test say;

$Userid = $ENV{'REMOTE_USER'};

if ($Userid eq "Dave"){$Daveloggedin = "True"};
if ($Userid eq "John"){$Daveloggedin = "True"};

because the $ENV{'REMOTE_USER'}; is only local isnt it? Or does it pick up from the server and can have more than just my login at the time?
The %ENV hash is a global, not a local. If I were using .htacess/.htpasswd for authentication I would just check for the existance of the 'REMOTE_USER' hash key:

Code:
$ENV{'REMOTE_USER'} or return login();
If you need to keep a list of users, something like this will work:
Code:
# If the user is not logged in, send them to the login page
$ENV{'REMOTE_USER'} or return login();

# Add the user name to a hash to keep track of users.
$USER{$ENV{'REMOTE_USER'}}++
That will populate a user hash with user names that you can iterate through but then you come back to your original problem. What happens if they don't log out like good litte users? You can expand the hash to include a time stamp:

Code:
# If the user is not logged in, send them to the login page
$ENV{'REMOTE_USER'} or return login();

# Add the user name to a hash to keep track of users.
$USER{$ENV{'REMOTE_USER'}} = time;
Then when you iterate though the list you can compare the timestamp to the currect time. If it's more than say, 30 minutes, or how ever long you want a session to last, you just remove them from the hash:

Code:
sub online {
  my @valid_users;
  foreach my $user (keys %USERS) {
    if ($USERS{$user} > time - 60 * 30) {
      # The user is still logged in
      push @valid_users, $user;
    }
    else {
      #They haven't done anything in 30 minutes, give em the boot
      delete $USERS{$user};
    }
  }
  return @valid_users;
}
This is all untested code so you might have to fix a few things but that gives you the general idea.

I like to use forms and sessions for user auth instead of .htaccess/.htpasswd. I don't like the pop-up box. Check into CGI::Session if you want a more robust way to manage sessions.

~Charlie
Reply With Quote
Reply

Bookmarks


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

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PlaceHolder Control kamlesh_nadar ASP.NET 6 10-12-06 07:26 AM
Lost ViViper1 Script Requests 5 11-18-03 05:57 PM
So lost....[assistance plz!] avnos HTML/XHTML/XML 4 11-15-03 03:05 AM
Completely lost.... VestanPance General HotScripts Site Discussion 1 10-08-03 04:36 AM
Lost listings? raz0 Hot Scripts Forum Questions, Suggestions and Feedback 6 06-22-03 09:47 AM


All times are GMT -5. The time now is 04:48 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.