Php $ _ SERVER [orig_script_name] is a new function of a project, which is implemented by the new framework developed by the company.
This framework is very NB. where is NB. There are several points:
1. this framework has no documentation;
2. there is no comment in the framework source code;
3. in addition to the main line developers, few of our departments are familiar with this feature;
If you want to use this framework to do things, there is only one way: look at the source code, first understand the implementation principle of the framework, and then use this bird to do things.
When I saw a request processing class, the following code came into view:
1 static function get_base_url(){ 2 $filename = ( isset ( $_SERVER [ ' SCRIPT_FILENAME ' ])) ? basename ( $_SERVER [ ' SCRIPT_FILENAME ' ]) : '' ; 3 if ( isset ( $_SERVER [ ' ORIG_SCRIPT_NAME ' ]) && basename ( $_SERVER [ ' ORIG_SCRIPT_NAME ' ]) === $filename ) { 4 $base_url = $_SERVER [ ' ORIG_SCRIPT_NAME ' ]; 5 } elseif ( isset ( $_SERVER [ ' SCRIPT_NAME ' ]) && basename ( $_SERVER [ ' SCRIPT_NAME ' ]) === $filename ) { 6 $base_url = $_SERVER [ ' SCRIPT_NAME ' ]; 7 } elseif ( isset ( $_SERVER [ ' PHP_SELF ' ]) && basename ( $_SERVER [ ' PHP_SELF ' ]) === $filename ) { 8 $base_url = $_SERVER [ ' PHP_SELF ' ]; 9 } else { 10 $path = isset ( $_SERVER [ ' PHP_SELF ' ]) ? $_SERVER [ ' PHP_SELF ' ] : '' ; 11 $file = isset ( $_SERVER [ ' SCRIPT_FILENAME ' ]) ? $_SERVER [ ' SCRIPT_FILENAME ' ] : '' ; 12 $segs = explode ( ' / ' , trim ( $file , ' / ' )); 13 $segs = array_reverse ( $segs ); 14 $index = 0 ; 15 $last = count ( $segs ); 16 $base_url = '' ; 17 do { 18 $seg = $segs [ $index ]; 19 $base_url = ' / ' . $seg . $base_url ; 20 ++ $index ; 21 } while (( $last > $index ) && ( false !== ( $pos = strpos ( $path , $base_url ))) && ( 0 != $pos )); 22 } 23 24 $request_uri = self :: get_request_uri(); 25 if ( 0 === strpos ( $request_uri , $base_url )) { 26 return self :: dirname ( $base_url ); 27 } 28 if ( 0 === strpos ( $request_uri , dirname ( $base_url ))) { 29 return self :: dirname ( $base_url ); 30 } 31 32 $truncatedrequest_uri = $request_uri ; 33 if (( $pos = strpos ( $request_uri , ' ? ' )) !== false ) { 34 $truncatedrequest_uri = substr ( $request_uri , 0 , $pos ); 35 } 36 37 $basename = basename ( $base_url ); 38 if ( empty ( $basename ) || ! strpos ( $truncatedrequest_uri , $basename )) { 39 return ; 40 } 41 42 if (( strlen ( $request_uri ) >= strlen ( $base_url )) 43 && (( false !== ( $pos = strpos ( $request_uri , $base_url ))) && ( $pos !== 0 ))) { 44 $base_url = substr ( $request_uri , 0 , $pos + strlen ( $base_url )); 45 } 46 return rtrim (self :: dirname ( $base_url ) , ' / ' ); 47 }
There are so many things to learn. Today, we saw the variable $ _ SERVER ['orig _ SCRIPT_NAME '] for the first time. What do you do? I don't know.
Previously, I only knew the variable $ _ SERVER ['script _ name.
I have always been the root of my research. What is unclear? if I don't get it out, it's hard to get it out.
You searched for the following section:
To know whether PHP is currently running through CGI or inside Apache, check the environment variable orig_script_name.
If PHP runs through CGI, the value of this variable is/Php/Php.exe.
If Apache runs the PHP script as a module, the value of this variable should be/Phptest. php.
This makes us suddenly realize. This is the reason.
It seems that it takes some time to learn php well.
Note.