Advertisement
pbowers

UserSpice: Redirect.php - allow args, fix relative paths

Sep 7th, 2016
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.84 KB | None | 0 0
  1. <?php
  2. /*
  3. UserSpice 4
  4. An Open Source PHP User Management System
  5. by the UserSpice Team at http://UserSpice.com
  6.  
  7. This program is free software: you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation, either version 3 of the License, or
  10. (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program.  If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. class Redirect {
  21.     public static function to($location = null, $args=''){
  22.         global $us_url_root;
  23.         #die("Redirecting to $location<br />\n");
  24.         if ($location) {
  25.             if (is_numeric($location)) {
  26.                 switch ($location) {
  27.                     case '404':
  28.                         header('HTTP/1.0 404 Not found');
  29.                         include 'includes/errors/404.php';
  30.                         break;
  31.                 }
  32.             }
  33.             if (!preg_match('/^https?:\/\//', $location) && !file_exists($location)) {
  34.                 foreach (array($us_url_root, '../', 'users/', substr($us_url_root, 1), '../../', '/', '/users/') as $prefix) {
  35.                     if (file_exists($prefix.$location)) {
  36.                         $location = $prefix.$location;
  37.                         break;
  38.                     }
  39.                 }
  40.             }
  41.             if ($args) $location .= $args; // allows 'login.php?err=Error+Message' or the like
  42.             if (!headers_sent()){
  43.                 header('Location: '.$location);
  44.             exit();
  45.         } else {
  46.         echo '<script type="text/javascript">';
  47.         echo 'window.location.href="'.$location.'";';
  48.         echo '</script>';
  49.         echo '<noscript>';
  50.         echo '<meta http-equiv="refresh" content="0;url='.$location.'" />';
  51.         echo '</noscript>'; exit;
  52.         }
  53.         }
  54.     }
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement