Forum Moderators: coopster & phranque

Message Too Old, No Replies

Perl script for conditional redirect per viewing session

To ensure that visitors are always directed to an entry/disclaimer page

         

WolfsonUK

11:32 am on Jan 21, 2004 (gmt 0)

10+ Year Member



I am absolutely new to Perl/cgi scripting, and searching the net unfortunately hasn't answered my paticular questions yet so I thought I'd ask the cracks in here :-)

(I do have a fair bit of experience in html, javascript, css and did C/C++ many moons ago so I'm not a total newbie to coding).

I need a solution that will redirect vistors of my site to my homepage once per viewing session, whenever they access one of the content pages directly. (This is important so that they can read and accept a disclaimer). So far I've used framed sites and javascript for this, with a check on each page in the form of

if (top==self) self.location.href='index.html';

Of course this doesn't work if javascript is disabled in the visitors browser, and I would also like to avoid using frames only for this purpose.

So the question is, can a perl cgi script check - whenever any of my pages is accessed - if the visitor has been on my index.html page during the current viewing session, and if yes allow him to view any page; if not than redirect him to index.html (assuming that he/she tried to access any of my other pages directly)? Particularly I am wondering if

- this could be done by setting and checking a variable which confirms that the visitors has been to index.html
- if so, do I have to create individual variables for all visitors who might be logged on at the same time (e.g. by including their IP in the variable)?
- last not least, how would I clear this variable when the vistors leave my domain, to start the process all over again when they come back?

Or do I have to go a completely different route? As I said I am totally new to cgi scripting and don't know the details (though I think I have a clue about the very basic concepts and purposes)?

Thanks in advance for any help!

SeanW

9:40 pm on Jan 21, 2004 (gmt 0)

10+ Year Member



Hi,

My first thought would be to set a session cookie through a perl script in your disclaimer page (look at the CGI.pm docs for an example). The rest of your site uses a rewrite rule that sends the user to the page if they don't have the cookie (assuming apache here)

RewriteCond %{HTTP_COOKIE} "disclaimer"
RewriteRule "^.*$" "http://mysite.com/cgi-bin/readdisclaimer.cgi" [R]

readdisclaimer.cgi would set the cookie "disclaimer=yes" or something like that.

(that's my untested stab at it)

Good luck,

Sean