Gossamer Forum
Home : General : Perl Programming :

Apache question

Quote Reply
Apache question
Does anyone have a solution to the following:

1. Surfer calls site. Site creates cookie: user=value. For example: user=12345
2. File also created on server named as cookie value. For example: 12345.dat
3. If user calls specific directory (any file, or nested subdirectory), cookie retrieved by server. If cookie value not found to exist as file (e.g., 12345.dat), user redirected to specific URL.

This has to be handled per directory via .htaccess. I'm thinking using the Apache SetEnvIf directive in conjunction with Rewrite. Something like:

SetEnvIf Cookie ".*user=(.*)" user=$1
RewriteEngine on
RewriteCond /full/path/to/data/${ENV:user} !-f
RewriteRule /* /some_page.html [L,R]

However, this does not work. Any suggestions from the Apache gurus?



Cheers - Dan Cool

----
Cheers,

Dan
Founder and CEO

LionsGate Creative
GoodPassRobot
Magelln
Post deleted by RedRum In reply to

Last edited by:

RedRum: Feb 11, 2002, 12:47 PM
Quote Reply
Re: [dan] Apache question In reply to
Hmmm Im no Apache guru but how about:

SetEnvIf Cookie ".*user=(.*)" user=$1
RewriteEngine on
RewriteCond /full/path/to/data/$1 !-e
RewriteRule ^.* /some_page.html [L,R]
Quote Reply
Re: [RedRum] Apache question In reply to
Thanks Paul, but no go. Ran into same problem as I had before. $1 is undefined. It seems pattern memory does not work in SetEnvIf regex.



Cheers - Dan Cool

----
Cheers,

Dan
Founder and CEO

LionsGate Creative
GoodPassRobot
Magelln
Quote Reply
Re: [dan] Apache question In reply to
I had a feeling it wouldn't work and I can't test either as I'm having probs with Apache2.

Last edited by:

RedRum: Feb 11, 2002, 1:13 PM
Quote Reply
Re: [RedRum] Apache question In reply to
Yep, I had the same doubts with my code. Next batter up :) GT staffer?



Cheers - Dan Cool

----
Cheers,

Dan
Founder and CEO

LionsGate Creative
GoodPassRobot
Magelln
Quote Reply
Re: [dan] Apache question In reply to
Can you do this using a CGI script? Check the cookie that was sent, check if file exists, and if not throw an error.

Why the need to make this an Apache problem with mod_rewrite ??

- wil
Quote Reply
Re: [dan] Apache question In reply to
This may sound stupid but you do have mod_setenvif uncommented in httpd.conf don't you?
Quote Reply
Re: [Wil] Apache question In reply to
Thanks, but it has to be implemented via Rewrite. So if user requests any file (HTML and non-HTML) in a certain directory, they are issued a cookie if one is not found on their computer. Otherwise if the cookie does exist, the value is checked if it exists as a file.



Cheers - Dan Cool

----
Cheers,

Dan
Founder and CEO

LionsGate Creative
GoodPassRobot
Magelln
Quote Reply
Re: [RedRum] Apache question In reply to
Thanks but yep (the first thing I checked). Plus, I also verified SetEnvIf is available per directory by setting up simple implementation (prevention of hotlinking of images by checking referer when images requested) - worked as expected. Besides, if it was not, one would expect an error calling a directive for a module not compiled into Apache.



Cheers - Dan Cool

----
Cheers,

Dan
Founder and CEO

LionsGate Creative
GoodPassRobot
Magelln