Hi ktgoh,
you don't tell the browser about the session id. Why?
To use a session id that's appended to the URL is hard work - it has to be
maintaned in every module and html file. So you must append the session id to
every URL in every page and every piece of code that produces html. Ther is no
way to automatically "keep" the id sticky.
A better way for session ids is to put them in front of the URI:
http://www.nus.edu.sg/dfd3453/some/path/and/file.html
This is (part of) my uri-translation-handler:
sub handler ($r: Apache) {
# only do initial request - not an internal sub req
return DECLINED unless $r->is_initial_req;
return DECLINED unless $r->uri =~ m/$DIR_MATCH/o;
try my $check_uri = &check_uri($r);
return DECLINED if $check_uri; # URI contains session id and session object
could be read from the DB
# else redirect to mangled URI
try my $session_id = &make_session_id($r);
&redirect($r, $session_id);
return REDIRECT;
# end of main handler
}
sub check_uri ($r: Apache) {
my $uri = $r->uri || undef;
my (undef, $sessionid, $rest) = split '/', $uri, 3;
if ($sessionid && $sessionid =~ m/^[0-9a-h]{32,32}$/o) {
$r->uri("/$rest");
try void &lock_session_id($r, $sessionid);
return 1;
}
return undef;
}
sub redirect ($r: Apache, $session_id: string min 32 max 32) {
my $args = $r->args ? '?' . $r->args : '';
my $uri = $r->parsed_uri;
$redirect = $uri->scheme . '://' . $uri->$hostinfo . '/'. $session_id . '/' .
$uri->path . $args;
$r->header_out(Location => $redirect);
}
These session ids are sticky as long as you only use relative paths in your
html. Note: You may want to put your images in a directory that's not covered by
this handler and use absolute paths...
Datum: 22.05.2001 12:03
An: "mod_perl" <[EMAIL PROTECTED]>
Betreff: Appending Sessionid to all the urls
Nachrichtentext:
Hi all :
I wanted to write a mod URL rewrite program.
I wanted to append session ID to the tail of all the urls of a website.
For instance when i access url http://www.nus.edu.sg?sessionid=dfd3453
i want all the urls to be appended in all the urls of that website..
My qns is everytime i found that the session id is lost... through the many
requests and responses.
And the new url does not reflect on the client browser..
Any one got any idea.. what wrong with my program??
Thanks for your help...
sub handler {
my $r = shift;
my $url = $r->uri;
my $sessID;
if($url =~ m/sessionid/){
$sessID= getSessionID($url);
}
my $append =?sessionid=$sessID
my $newURL = $r->uri($url$append);
return DECLINED;
}
sub getSessionID{
my $url = $_[0];
my $position = rindex($url,"=")+1;
my $sessID = substr($url,$position,8);
return $sessID;
}
Regards
kheeteck