i2-Services, Inc. Forums

Full Version: How To Tip: Redirect to folder based on username index page / script
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Thought I would add this for anyone looking to do a redirect based on username when using .htaccess
basic authentication.

This is good if you're looking to have for example:

http://www.website.com/members/

and redirect them upon logging in to /members/ be directed to their
own folder:

Name this "index.php"  within the /members/ folder.

PHP Code:
<?php
  
   $folder
= $_SERVER[REMOTE_USER];

   header("Location: http://www.your-domain.com/members/$folder/");
  
?>

I can vouch for this working - it saved me a load of time and makes the log in process much more professional & slick.

Dave.
I'll provide code for a index.shtml page as well which will do the redirect just the same:

<html>
<meta http-equiv="refresh" content="0;url=http://www.web-address.com/members_folder/<!--#echo var="remote_user" -->/">
</html>
Does this only work for ".htaccess basic authentication" how about the mod rewrite system?
This is for .htaccess. Its possible with the mod_rewrite option.  You would just use PHP code and do a redirect based on the

$_SESSION[mm_email]  variable.
so i would have to use *.php pages then. Bugger, as i use html Sad
Just a index.php with probably 4 lines of code on it which would be in for example:

.com/members/ (index.php)

which redirects to:

.com/members/email@address.com/

i2-Services, Inc. Wrote:

PHP Code:
<?php
   
   $folder
= $_SERVER[REMOTE_USER];

   
header("Location: http://www.your-domain.com/members/$folder/");
  
?>


So how would I define which users gets redirected? Is "remote_user" an email of a registered user? what about if I wanted to redirect more than one person? Or redirect an entire group?

I guess then, if "remote_user" doesn't match any of the criteria, the rest of the page loads as per normal?

Ronnie

Depends on what protection method you're using. Standard .htaccess basic authentication you can only pull in the username & redirect based on that.

The remote user is the username on the account. In v1.x it normally is the e-mail address. Version 2.x now allows you to ask for a unique username during registration.

If you're using mod_rewrite you can check the session variable "mm_lists" which contains the groups they belong to and do a redirect based on that.
Reference URL's