Bryan

            BlogJava :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
            37 Posts :: 3 Stories :: 24 Comments :: 0 Trackbacks
          There is one perl cgi system which runs on apache server,It's open to everyone and no users stored in file systems or Databases, client wants to know how many users are using this system. How?

          The only way I know is to use CGI::Session and cookie. each time,one client uses the system, we are using the CGI::Session to create one session , and this session should not duplicate for one user who are using the same browser(IE eg), and of course may differ for different browsers. The session will create session files in specified temp folder. each new session ,one session file. Then we can use one pl script to list active users ,actually ,that should be the number of session files in the session directory. And one thing we need to do is that we need to delete the expired session files before we want to compute the number of active users. we can use the module CGI::Session::ExpireSessions and delete the session files according to the session time-out age.

          $D = {'_SESSION_ID' => '772278a8aa05506449b4e72582d09f95','_SESSION_ATIME' => 1366012456,'_SESSION_REMOTE_ADDR' => '135.251.33.31','_SESSION_CTIME' => 1366012456};;$D

          session.pl
          #!C:/Perl/bin/perl

          use strict;
          use CGI;
          use warnings;
          use CGI::Session;

          #create session,if exists,use that one
          my $cgi = CGI->new;
          my $session = CGI::Session->new( undef, $cgi, {Directory=>'c:/tmp'} );

          my $cookie = $cgi->cookie(CGISESSID => $session->id );
          print $cgi->header(-cookie=>$cookie);
          my $sid = $session->id();
          #print $sid;
          #set session expired date
          #$session->expire(30);     
          print "  <a href=\"count.pl?sid=$sid\">list active users</a>";

          count.pl
          #!C:/Perl/bin/perl

          use strict;
          use CGI;
          use warnings;
          use File::Find::Rule;
          use CGI::Session;
          use CGI::Session::ExpireSessions;

          print "Content-type: text/html\n\n";

          #clear expired session
          CGI::Session::ExpireSessions -> new(delta => 30, temp_dir => 'c:\tmp', verbose => 0-> expire_file_sessions();

          my @files = File::Find::Rule->file()->in('c:\tmp');
          print "The number of active users is : ";
          print scalar @files, $/;

          I suppose the count.pl are always using the same session with the session.pl.And we need to also install the module File::Find::Rule.

          Apache HTTP Server Version 2.0 
          ActivePerl 5.16.3 Build 1603
          ActiveState Komodo Edit 7


          posted on 2013-04-15 15:58 Life is no respector of any genius. 閱讀(296) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 富蕴县| 康马县| 合江县| 宣城市| 海林市| 南靖县| 伊金霍洛旗| 金山区| 珠海市| 朝阳市| 郧西县| 云阳县| 威远县| 锦州市| 同江市| 永兴县| 东方市| 马龙县| 靖边县| 子洲县| 噶尔县| 射洪县| 石台县| 勃利县| 泰州市| 乌兰浩特市| 蚌埠市| 邢台市| 平塘县| 桐乡市| 且末县| 安陆市| 历史| 驻马店市| 穆棱市| 宁明县| 铁力市| 钟山县| 福泉市| 大同县| 宣城市|