Advertisement
Guest User

junksmi

a guest
Dec 23rd, 2008
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.63 KB | None | 0 0
  1. <?php
  2.  
  3. //redirect.php
  4. // NON EXISTING DIRS WILL STILL DEFAULT TO USER
  5. // NON EXISTING FILES WILL GIVE A 404 error...  - BUT ONLY IF IN USERS OWN DIR
  6.  
  7. ob_start();
  8. $inroot = 0;
  9.  
  10. //the original request from client
  11. $loca = "http://".$_SERVER['SERVER_NAME'].$_SERVER['QUERY_STRING'];
  12.  
  13. // just the querystring -  default location to redirect to
  14. $loctogo = $_SERVER['QUERY_STRING'];
  15. $trtlevel = 1; //can be eventually used for several levels
  16.  
  17. // default path / location
  18. $locuser = "/".$_SERVER['REMOTE_USER']."/";    
  19.  
  20. //leave admin alone
  21. if ($_SERVER['REMOTE_USER'] != "admin")
  22. {
  23.     if ($_SERVER['REQUEST_URI'] == '/')
  24.     {
  25.         //echo "we are in root<br>";
  26.         $inroot = 1;
  27.  
  28.         //redirect each user to their home dir
  29.         $loctogo = $locuser;
  30.         $trtlevel = 1;
  31.        
  32.     }
  33.     else
  34.     {
  35.         // echo "we are not in root<br>";
  36.         // check if user and subdir match
  37.        
  38.         // check if current user is below users home
  39.         $str = $_SERVER['REQUEST_URI'];
  40.         $pat = "/".$_SERVER['REMOTE_USER']."/";
  41.         $regs = array();
  42.         $usrsubdir = "";
  43.        
  44.         if(ereg($pat,$str,$regs)) {
  45.             //echo "match: ".$regs[0]."<br>\n"; // $regs[0] == "/pubx/"
  46.             $usrsubdir = $regs[0];
  47.         }
  48.        
  49.         if($usrsubdir == "") {
  50.             // no match, return user to users 'home'
  51.             $loctogo = $locuser;
  52.             $trtlevel = 1;             
  53.         }
  54.         else
  55.         {
  56.             // they match, continue
  57.             // do nothing - $loctogo should be = $_SERVER['QUERY_STRING'];
  58.         }
  59.     }
  60. }
  61.  
  62. // make headers for redirection and cookie
  63. // cookie will expire in 1 second
  64. header("referer: ".$loca."\r\n");
  65. header("location: ".$loctogo);
  66. $in2secs = 1 + time();
  67. setcookie('troute', $trtlevel, $in2secs);
  68.  
  69. ob_end_flush();
  70.    
  71. ?>
  72.  
  73.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement