yschang has asked for the wisdom of the Perl Monks concerning the following question:

Hi: The following is what I need to do: After user login, I send a user id cookie to the client, then in every html page, I use a SSI to include a perl file to retrieve the user id from client, see wether he/she is O.K to access this html page or not. However, I can't get cookie value by doing this. It seems to me only when use perl file as a CGI not a include, then I can get cookie value. Is there a SAMPLE way to do this task? I am using CGI model. The reason I am using a server side include is to protect the file in case someone direct access this file by bookmarking or something like that. I know you can do this by configure the server, but this is not the case to use server configuration since we have a user database. Thanks

Replies are listed 'Best First'.
Re: How I get cookie value
by mortis (Pilgrim) on Feb 04, 2000 at 02:49 UTC
    I'd think you can still use CGI.pm -- with the cookie() method to retreive the cookie:
    my $q = new CGI; my $val = $q->cookie('param');
    If you're not using CGI.pm (or can't for some reason), you can get the HTTP_COOKIE from the program's environment (unless ssi is clearing the environment out):
    my $http_cookie = $ENV{'HTTP_COOKIE'}; $http_cookie =~ /^([^=]+)=(.*)$/; my($name,$val) = ($1,$2);
    hope this helps...
      how does that piece of code know what cookie you are after. I tried it and it got a value of null.
      Thanks. But as matter of fact I use CGI model did what you did. It didn't work. Also I try to use %ENV, also it didn't give me back anything as long as I use it in a SSI. Maybe just like you said netscape server SSI did something. But I am stuck here. Is there other way using perl to this job beside using server configuration. Thanks
Re: How I get cookie value
by Anonymous Monk on Jun 16, 2001 at 00:02 UTC
    SSI runs your script to get the text and includes that text. It does *not* include your perl-Script into another one. And your script as SSI can *not* prevent the including file from being sent.