Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

If I set a cookie on a client, and I want that cookie to determine what page loads when the user types in www.webpage.com, how would I do it? I would have to have a PERL script load automatically with the index.html page to analyze the cookie and redirect based on the cookie's value, no? Is that the only way?

Thanks.

Replies are listed 'Best First'.
Re: redirection based on cookie
by ccn (Vicar) on Sep 15, 2004 at 12:58 UTC
Re: redirection based on cookie
by doowah2004 (Monk) on Sep 15, 2004 at 13:24 UTC
    You can use JavaScript. Google 'javascript cookies' and 'javascript redirect' to see good examples. The problem with this is that the client could have javascript turned off, in that case you could have the webpage detect that and display a message telling the client to turn it on.

    The other way is to have the page be a perl script, i.e. if it is the index page, remove index.htm or index.html and use index.cgi or index.pl. You will need to have those index pages set up in apache's cfg (or what ever webserver you are using) to be displayed as an index page. Lots of info on this if you search around.

    I hope that this helps, and good luck,

    Cameron
Re: redirection based on cookie
by borisz (Canon) on Sep 15, 2004 at 17:29 UTC
    I would use a PerlHandler that examine the cookie and then do this or that. Since I use mod_perl.
    Boris
Re: redirection based on cookie
by ercparker (Hermit) on Sep 21, 2004 at 07:38 UTC
    if you are going to use perl to check if a cookie has been set and are using
    apache, you can modify the httpd.conf file and set the
    DirectoryIndex to index.cgi or .pl or whatever you want. If you don't have
    access to the conf file you can more than likely set the DirectoryIndex in a
    .htaccess file.
    There are many ways you can redirect a user based on a set cookie.
Re: redirection based on cookie
by amt (Monk) on Sep 15, 2004 at 15:41 UTC
    If you wish to use the Perl implementation of cookies, and avoid javascripting or configuration changes, as mentioned here by doomwah2004 considered adding META tags to your HTML HEAD block. You should look here and then write your redirection script using CGI.pm.

    amt