Php $ _ SERVER ['orig _ script_name ']

Source: Internet
Author: User
The main points are as follows: 1. there is no documentation for the framework; 2. there is no comment in the source code of the framework; 3. few people in our department are familiar with the use of this framework except for the main line developers; 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 see a request processing class, the following code comes into view: staticfunctionget_base_url () {mainly has the following 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:

 static function get_base_url(){         $filename = (isset($_SERVER['SCRIPT_FILENAME'])) ? basename($_SERVER['SCRIPT_FILENAME']) : '';          if (isset($_SERVER['ORIG_SCRIPT_NAME']) && basename($_SERVER['ORIG_SCRIPT_NAME']) === $filename) {             $base_url = $_SERVER['ORIG_SCRIPT_NAME'];           } elseif (isset($_SERVER['SCRIPT_NAME']) && basename($_SERVER['SCRIPT_NAME']) === $filename) {              $base_url = $_SERVER['SCRIPT_NAME'];          } elseif (isset($_SERVER['PHP_SELF']) && basename($_SERVER['PHP_SELF']) === $filename) {             $base_url = $_SERVER['PHP_SELF'];          } else {             $path    = isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : '';             $file    = isset($_SERVER['SCRIPT_FILENAME']) ? $_SERVER['SCRIPT_FILENAME'] : '';             $segs    = explode('/', trim($file, '/'));             $segs    = array_reverse($segs);             $index   = 0;            $last    = count($segs);            $base_url = '';             do {                 $seg = $segs[$index];                 $base_url = '/' . $seg . $base_url;                 ++$index;             } while (($last > $index) && (false !== ($pos = strpos($path, $base_url))) && (0 != $pos));         }                  $request_uri = self::get_request_uri();         if (0 === strpos($request_uri, $base_url)) {             return self::dirname($base_url);         }        if (0 === strpos($request_uri, dirname($base_url))) {             return self::dirname($base_url);         }                 $truncatedrequest_uri = $request_uri;        if (($pos = strpos($request_uri, '?')) !== false) {             $truncatedrequest_uri = substr($request_uri, 0, $pos);         }                 $basename = basename($base_url);         if (empty($basename) || !strpos($truncatedrequest_uri, $basename)) {             return;        }                 if ((strlen($request_uri) >= strlen($base_url))         && ((false !== ($pos = strpos($request_uri, $base_url))) && ($pos !== 0)))  {            $base_url = substr($request_uri, 0, $pos + strlen($base_url));         }                    return  rtrim(self::dirname($base_url), '/');     }

12 Next page

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.