You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by ktgoh <kt...@newstakes.com> on 2001/05/22 12:06:17 UTC

Appending Sessionid to all the urls

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






Re: Appending Sessionid to all the urls

Posted by Jay Jacobs <ja...@lach.net>.
there's always more then one way...

DocumentRoot "/usr/local/apache_mp/htdocs"
RewriteEngine On
RewriteCond /usr/local/apache_mp/htdocs/%{REQUEST_FILENAME} !-f
RewriteRule /?S=([^/]+)/(.*) /$2 [E=SESSION_ID:$1]

This sets $ENV{SESSION_ID} to the session ID, but also catches it, if by
some bizarre and unlikely circumstance your have a directory that matches
someone's Session ID.  In this case the session is:
http://host.domain.com/S=asdfasdf/path/requested.pl

Using mod rewrite also munges the $r->filename which helped things like
mason that looked for it (don't know if it still does).

Jay


On Tue, 22 May 2001, Joachim Zobel wrote:

> At 18:06 22.05.2001 +0800, you wrote:
> >
> >For instance when i access url
> ><http://www.nus.edu.sg?sessionid=dfd3453>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??
> >
>
> Wrong concept.
> Use a sid in the URL path like
> http://www.nus.edu.sg/sessionid-dfd3453/this/is/it.pl
> Use mod_rewrite to remove /sessionid-\w+
> Use only relative links.
>
> Thats it. You can get the sessionid by parsing $ENV{REQUEST_URI}
>
> Hth,
> Joachim
>
> --
> "... ein Geschlecht erfinderischer Zwerge, die fuer alles gemietet werden
> koennen."                            - Bertolt Brecht - Leben des Galilei
>
>


Re: Appending Sessionid to all the urls

Posted by Joachim Zobel <nc...@netcologne.de>.
At 18:06 22.05.2001 +0800, you wrote:
>
>For instance when i access url 
><http://www.nus.edu.sg?sessionid=dfd3453>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??
>

Wrong concept.
Use a sid in the URL path like 
http://www.nus.edu.sg/sessionid-dfd3453/this/is/it.pl
Use mod_rewrite to remove /sessionid-\w+
Use only relative links.

Thats it. You can get the sessionid by parsing $ENV{REQUEST_URI}

Hth,
Joachim

--
"... ein Geschlecht erfinderischer Zwerge, die fuer alles gemietet werden
koennen."                            - Bertolt Brecht - Leben des Galilei