Guest User

Untitled

a guest
Jun 22nd, 2018
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. ## Original
  2. <?php
  3. if(isset($_FILE_TO_URL_MAPPING)) {
  4. $fullPath = $testPath = $_SERVER['SCRIPT_FILENAME'];
  5. while($testPath && $testPath != "/") {
  6. if(isset($_FILE_TO_URL_MAPPING[$testPath])) {
  7. $url = $_FILE_TO_URL_MAPPING[$testPath] . substr($fullPath,strlen($testPath));
  8. $_SERVER['HTTP_HOST'] = parse_url($url, PHP_URL_HOST);
  9. $_SERVER['SCRIPT_NAME'] = $_SERVER['PHP_SELF'] = parse_url($url, PHP_URL_PATH);
  10. $_SERVER['REQUEST_PORT'] = parse_url($url, PHP_URL_PORT);
  11. break;
  12. }
  13. $testPath = dirname($testPath);
  14. }
  15. }
  16.  
  17.  
  18. ## Fixed version
  19. <?php
  20. if(isset($_FILE_TO_URL_MAPPING)) {
  21. $fullPath = $testPath = $_SERVER['SCRIPT_FILENAME'];
  22. while($testPath && $testPath != dirname($testPath)) {
  23. if(isset($_FILE_TO_URL_MAPPING[$testPath])) {
  24. $url = $_FILE_TO_URL_MAPPING[$testPath] . substr($fullPath,strlen($testPath));
  25. $_SERVER['HTTP_HOST'] = parse_url($url, PHP_URL_HOST);
  26. $_SERVER['SCRIPT_NAME'] = $_SERVER['PHP_SELF'] = parse_url($url, PHP_URL_PATH);
  27. $_SERVER['REQUEST_PORT'] = parse_url($url, PHP_URL_PORT);
  28. break;
  29. }
  30. $testPath = dirname($testPath);
  31. }
  32. if ( !isset($url) ) {
  33. die("Cannot map to URL. Please check global \$_FILE_TO_URL_MAPPING is set correctly (in particular the slashes)");
  34. }
  35. }
Add Comment
Please, Sign In to add comment