Bluehost.com Web Hosting $6.95

HTTP_COOKIE problem

This is a discussion on HTTP_COOKIE problem within the Apache Web Server forums, part of the Web Server and Related Forums category; Hi I want to do some hash on the HTTP_COOKIE string which gives me a value between 1 to 1000. ...


Go Back   Usenet Forums > Web Server and Related Forums > Apache Web Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-21-2006
manoj.agarwal.in@gmail.com
 
Posts: n/a
Default HTTP_COOKIE problem

Hi

I want to do some hash on the HTTP_COOKIE string which gives me a value
between 1 to 1000. For this I have written a perl script. Now I want to
call this perl script in my rewrite.conf (rewrite rule file) file in
apache. I am using RewriteMap for this but haven't succeeded. May be I
haven't understood using rewritemap well.
So my question is:

a. Can I reset my HTTP_COOKIE value in the rewrite.conf file?
b. Would calling a perl script be a good idea for this or is there any
other way around?
c. Can I write the logic of hashing within my conf file?


My conf file looks like:

RewriteMap cookie1 prg:/home/y/share/htdocs/cookie1.pl
RewriteRule ^/(index.html)?$ ${bcookie:$1} [L,PT]

Am I doing something wrong in this?

rgds
Manoj

  #2 (permalink)  
Old 02-21-2006
Duikboot
 
Posts: n/a
Default Re: HTTP_COOKIE problem

I am not sure, but shouldn't the rewrite rules be in a .htaccess file or
in the httpd.conf?

greetings,

Duikboot


manoj.agarwal.in@gmail.com wrote:
> Hi
>
> I want to do some hash on the HTTP_COOKIE string which gives me a value
> between 1 to 1000. For this I have written a perl script. Now I want to
> call this perl script in my rewrite.conf (rewrite rule file) file in
> apache. I am using RewriteMap for this but haven't succeeded. May be I
> haven't understood using rewritemap well.
> So my question is:
>
> a. Can I reset my HTTP_COOKIE value in the rewrite.conf file?
> b. Would calling a perl script be a good idea for this or is there any
> other way around?
> c. Can I write the logic of hashing within my conf file?
>
>
> My conf file looks like:
>
> RewriteMap cookie1 prg:/home/y/share/htdocs/cookie1.pl
> RewriteRule ^/(index.html)?$ ${bcookie:$1} [L,PT]
>
> Am I doing something wrong in this?
>
> rgds
> Manoj
>

  #3 (permalink)  
Old 02-21-2006
Robert Ionescu
 
Posts: n/a
Default Re: HTTP_COOKIE problem

Duikboot wrote:
> I am not sure, but shouldn't the rewrite rules be in a .htaccess file or
> in the httpd.conf?


httpd.conf should be always preferred for a better performance because
the RegEx is only compiled once at startup and not per each processing
of the .htaccess file. A RewriteMap cannot be defined in per-dir
context, so the directive must be placed in per-server context (main
server config section or virtualhost).

-> Avoid .htaccess files, if possible.

--
Robert
  #4 (permalink)  
Old 02-21-2006
Robert Ionescu
 
Posts: n/a
Default Re: HTTP_COOKIE problem

manoj.agarwal.in@gmail.com wrote:
> a. Can I reset my HTTP_COOKIE value in the rewrite.conf file?


Some environmental variables (i.e. document_root) cannot be changed via
the E-Flag or mod_setenv(if).

The RewriteMap only returns a value which is being insert here in the
substitution. I don't think that you can manipulate ENVs from the prg
lookup script.

The manual states this:
| For each map-function lookup it will receive the key to lookup as a
| newline-terminated string on stdin. It then has to give back the
| looked-up value as a newline-terminated string on stdout

Three options I can think of:
-> You're writing an other int function in mod_rewrite.c from where you
should have access to all apache internals

-> You can try to use the E-flag to set a ENV but as I said, i don't
think that you can override this variable here like

# escape literal periods
RewriteRule ^/(index\.html)?$ - [E=HTTP_COOKIE:${bcookie:$1}]

or if you can't place a map lookup within the E-flag (it's not
documented), I'd use something like

RewriteCond ${bcookie:$1} ^(.*)
RewriteRule ^/(index\.html)?$ - [E=HTTP_COOKIE:%1]

-> You're rewriting to some cgi-script which changes the variables and
then execute a program which returns some output like
exec /usr/bin/php ...somepath...

The difference here is you're in the last step of the processing
(content handler).

> Now I want to call this perl script in my rewrite.conf (rewrite rule
> file) file in apache.


Make sure that the rules are being executed, i.e. if you're using
virtualhosts, you must place the rules there, or you use
| RewriteEngine on
| RewriteOptions inherit

in your <virtualhost> to include/execute the rules from the main server
config section.

In order to check if the rules are being processed, I'd use a RewriteLog.

--
Robert
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 03:03 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0