Home     SSI Lab     CSS Templates     CSS     Htaccess     Web Design     XHTML





Introductory Topics

SSI Directives

Extending SSI


Top Resources

CSS Templates



Web Design




SSI User Redirection on Login


The following is required: when a user logs into a directory protected with .htaccess the user needs to be redirected to a particular page based on who the logged-in user is. One very easy way to do this is by using Conditional or Extensible SSI (don't ask me what the difference is!) which also allows us to build custom dynamic pages to suit.

Step 1 - Entry Point

Select your point of entry for the protected directory i.e. the page the user goes to after logging in. This page will contain the redirect codes, name it something simple like index.shtml or redirect.shtml. Don't forget the .shtml extension if you want the file to be parsed by the server. For the purposes of this guide i'm taking it that we are using SSI on ALL pages and therefore all have the extension .shtml!

There is a very handy script available which allows you to access .htaccess protected directories via a login form instead of the usual boring pop-up alert thingy! You can get it from a number of sites including - http://javascript.internet.com. Just search there for the "HTACCESS LOGIN" Script.

Step 2 - Redirecting

What we are going to do is simply check who the user is and include code to match. If that makes sense?
See Example 1 below.

Example 1::

<!--#if expr="$REMOTE_USER = 'user1'" -->
<META HTTP-EQUIV="Refresh" CONTENT="1; URL=user1/page.shtml">
<!--#elif expr="$REMOTE_USER = 'user2'" -->
<META HTTP-EQUIV="Refresh" CONTENT="1; URL=user2/page.shtml">
<!--#else -->
<META HTTP-EQUIV="Refresh" CONTENT="1; URL=denied.shtml">
<!--#endif -->

What this is basically saying is:
If the user who logged in (Remote_User) is user1 then include the Meta Refresh line which redirects user1 to user1/page.shtml,
Else if the user who logged in is user2 then redirect to user2/page.shtml,
Else redirect to denied.shtml.

Rather than redirect to another page you could choose to display user specific content or a link to a specific page, for example:

<!--#if expr="$REMOTE_USER = 'user1'" -->
Welcome user1, you will now be redirected to your personal page.
To access your page directly <a href="user1/page.shtml">click here</a>.
<!--#elif expr="$REMOTE_USER = 'user2'" -->
Welcome user2, you will now be redirected to your personal page.
To access your page directly <a href="user2/page.shtml">click here</a>.
<!--#else -->
Should you BE here? Problems email con@dom.com
<!--#endif -->

This gives the user a direct link to their specific page.

The above snippet of code would result in:

Welcome user1, you will now be redirected to your personal page.
To access your page directly click here.

Example 2::

The same effect as above can basically be accomplished with a single line of code:

<META HTTP-EQUIV="Refresh" CONTENT="1; URL=<!--#echo var="REMOTE_USER" -->.shtml">

or with a javascript version:

<script language="JavaScript">
if( -1 == location.href.
indexOf('<!--#echo var="REMOTE_USER" -->.shtml') )
location.href = '<!--#echo var="REMOTE_USER" -->.shtml';
// -->

The limitations with Example 3 is that ya gotta make sure to name the users page or directory the same as their login name which you don't need to do for the first example above!! So user1 must be redirected to user1.shtml or user1/, user johnthomas must be redirected to johnthomas.shtml or johnthomas/ etc

Advertisement Sign up for free to PayBox.me today and get $25 just for joining AND earn up to $20 per day for participating.