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) 評(píng)論(0)  編輯  收藏

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


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 台湾省| 天等县| 凯里市| 收藏| 宁陕县| 枣阳市| 黄浦区| 甘德县| 乡城县| 基隆市| 南漳县| 柯坪县| 宁波市| 大新县| 资阳市| 江城| 清河县| 卢湾区| 城口县| 黎平县| 吴川市| 河池市| 新田县| 德兴市| 大丰市| 邯郸市| 伽师县| 大邑县| 原阳县| 万荣县| 宝兴县| 遂川县| 恭城| 吴堡县| 聊城市| 财经| 襄樊市| 武功县| 澄迈县| 富蕴县| 营口市|