Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //redirect.php
- // NON EXISTING DIRS WILL STILL DEFAULT TO USER
- // NON EXISTING FILES WILL GIVE A 404 error... - BUT ONLY IF IN USERS OWN DIR
- ob_start();
- $inroot = 0;
- //the original request from client
- $loca = "http://".$_SERVER['SERVER_NAME'].$_SERVER['QUERY_STRING'];
- // just the querystring - default location to redirect to
- $loctogo = $_SERVER['QUERY_STRING'];
- $trtlevel = 1; //can be eventually used for several levels
- // default path / location
- $locuser = "/".$_SERVER['REMOTE_USER']."/";
- //leave admin alone
- if ($_SERVER['REMOTE_USER'] != "admin")
- {
- if ($_SERVER['REQUEST_URI'] == '/')
- {
- //echo "we are in root<br>";
- $inroot = 1;
- //redirect each user to their home dir
- $loctogo = $locuser;
- $trtlevel = 1;
- }
- else
- {
- // echo "we are not in root<br>";
- // check if user and subdir match
- // check if current user is below users home
- $str = $_SERVER['REQUEST_URI'];
- $pat = "/".$_SERVER['REMOTE_USER']."/";
- $regs = array();
- $usrsubdir = "";
- if(ereg($pat,$str,$regs)) {
- //echo "match: ".$regs[0]."<br>\n"; // $regs[0] == "/pubx/"
- $usrsubdir = $regs[0];
- }
- if($usrsubdir == "") {
- // no match, return user to users 'home'
- $loctogo = $locuser;
- $trtlevel = 1;
- }
- else
- {
- // they match, continue
- // do nothing - $loctogo should be = $_SERVER['QUERY_STRING'];
- }
- }
- }
- // make headers for redirection and cookie
- // cookie will expire in 1 second
- header("referer: ".$loca."\r\n");
- header("location: ".$loctogo);
- $in2secs = 1 + time();
- setcookie('troute', $trtlevel, $in2secs);
- ob_end_flush();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement