wp_fix_server_vars

Fix `$_SERVER` variables for various setups.

Description

wp_fix_server_vars(); 

Usage

  1. if ( !function_exists( 'wp_fix_server_vars' ) ) { 
  2. require_once ABSPATH . WPINC . '/load.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = wp_fix_server_vars(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/load.php  
  1. function wp_fix_server_vars() { 
  2. global $PHP_SELF; 
  3.  
  4. $default_server_values = array( 
  5. 'SERVER_SOFTWARE' => '',  
  6. 'REQUEST_URI' => '',  
  7. ); 
  8.  
  9. $_SERVER = array_merge( $default_server_values, $_SERVER ); 
  10.  
  11. // Fix for IIS when running with PHP ISAPI 
  12. if ( empty( $_SERVER['REQUEST_URI'] ) || ( PHP_SAPI != 'cgi-fcgi' && preg_match( '/^Microsoft-IIS\//', $_SERVER['SERVER_SOFTWARE'] ) ) ) { 
  13.  
  14. // IIS Mod-Rewrite 
  15. if ( isset( $_SERVER['HTTP_X_ORIGINAL_URL'] ) ) { 
  16. $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_ORIGINAL_URL']; 
  17. // IIS Isapi_Rewrite 
  18. elseif ( isset( $_SERVER['HTTP_X_REWRITE_URL'] ) ) { 
  19. $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL']; 
  20. } else { 
  21. // Use ORIG_PATH_INFO if there is no PATH_INFO 
  22. if ( !isset( $_SERVER['PATH_INFO'] ) && isset( $_SERVER['ORIG_PATH_INFO'] ) ) 
  23. $_SERVER['PATH_INFO'] = $_SERVER['ORIG_PATH_INFO']; 
  24.  
  25. // Some IIS + PHP configurations puts the script-name in the path-info (No need to append it twice) 
  26. if ( isset( $_SERVER['PATH_INFO'] ) ) { 
  27. if ( $_SERVER['PATH_INFO'] == $_SERVER['SCRIPT_NAME'] ) 
  28. $_SERVER['REQUEST_URI'] = $_SERVER['PATH_INFO']; 
  29. else 
  30. $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] . $_SERVER['PATH_INFO']; 
  31.  
  32. // Append the query string if it exists and isn't null 
  33. if ( ! empty( $_SERVER['QUERY_STRING'] ) ) { 
  34. $_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; 
  35.  
  36. // Fix for PHP as CGI hosts that set SCRIPT_FILENAME to something ending in php.cgi for all requests 
  37. if ( isset( $_SERVER['SCRIPT_FILENAME'] ) && ( strpos( $_SERVER['SCRIPT_FILENAME'], 'php.cgi' ) == strlen( $_SERVER['SCRIPT_FILENAME'] ) - 7 ) ) 
  38. $_SERVER['SCRIPT_FILENAME'] = $_SERVER['PATH_TRANSLATED']; 
  39.  
  40. // Fix for Dreamhost and other PHP as CGI hosts 
  41. if ( strpos( $_SERVER['SCRIPT_NAME'], 'php.cgi' ) !== false ) 
  42. unset( $_SERVER['PATH_INFO'] ); 
  43.  
  44. // Fix empty PHP_SELF 
  45. $PHP_SELF = $_SERVER['PHP_SELF']; 
  46. if ( empty( $PHP_SELF ) ) 
  47. $_SERVER['PHP_SELF'] = $PHP_SELF = preg_replace( '/(\?.*)?$/', '', $_SERVER["REQUEST_URI"] );