I could be misunderstanding, but i'm not sure it's possible since mod_rewrite only acts on "inbound" urls... So client logins into your site, thus establishing a session on the server. Now, the client asks for foo.html -- how could mod_rewrite know how to match this new client request (which could be from any client) with a session id on the server side? (no cookie, can't rely on remote IP, no info yet in query string)
I don't know if there's anything in perl/mod_perl/cgi-world that does the same transparent query string appending of session id that php can do (i hope so and that someone will mention it), but here's another alternative: You could write a filter for your outbound content that finds relative urls and appends the session id to the query string. I've used this method to encrypt query strings, so query strings don't look like
?year=3&type=search&btn=find but instead like
s=<somebignumber>. To set this up need the following:
need something like this in http.conf:
PerlModule Apache::Filter \
OurStuff::SessionFilter
<Directory "/www_doc_root/">
PerlHandler OurStuff::SessionFilter
SetHandler perl-script
</Directory>
And the OurStuff::SessionFilter looks like:
package OurStuff::SessionFilter;
use Apache::Constants();
sub handler {
my $r = shift;
$r = $r->filter_register();
my($fh, $status) = $r->filter_input();
return $status unless $status == Apache::Constants::OK();
my $session_id = OurStuff::Session->getCurrent()->id;
# now the hard part: process the $fh filehandle and
# find relative urls, and add &session=$session_id to
# the query string.
# keep in mind that urls can be embedded in javascript,
# such as location.href='...' or window.open(...)
return OK;
}
1;
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.