In ie, the Referer cannot be obtained when redirecting window. Location. href. The path in PHP contains an undetermined

Source: Internet
Author: User

For example, just record the uncertain path contained in PHP:

This is caused by the include path of PHP. Test it by yourself and summarize it as follows.

DefinitionA = include file B = file included by a c = file included by B
That is to say, a contains B, and B contains C.
A has

PHP code
  1. Require '[B path]' // (here, require can be changed to require_once include)
Require '[B path]' // (here, require can be changed to require_once include)

B has

PHP code
  1. Require '[c path]' // (here, require can be changed to require_once include)
Require '[c path]' // (here, require can be changed to require_once include)

The following discussion focuses on a as the entry file, that is, access a directly instead of B.

First, two concepts are defined:Relative PathAndFull path, I define them as relative paths referPath starting.For example
./A. php(Relative to the current directory)
../Common. Inc. php(Relative to the upper-level directory), the full path is a path starting with/or similar to a drive letter in Windows. The full path can uniquely determine the final address of the file without any reference path. For example
/Apache/wwwroot/site/a/A. php
C:/wwwroot/site/a/A. php
Are there other types of paths besides relative paths and full paths? And. Any path that does not start with a. Or/or a drive letter in Windows:/, for example
A/A. phpCommon. Inc. php, Such a path is the third type path. Initially, this is a relative path, but in the include/require inclusion mechanism of PHP, this type of path is completely different from the processing of the relative path starting. (Require './A. php' and require 'a. php' are different !) Let's call this pathUncertain Path

The following describes how to handle these three types of paths: first, remember a conclusion: If the path contains a relative or full path, the file will not be searched in include_path, that is, regardless of PHP. what is the environment variable include_path defined in ini, or set set_include_path (...) in the program (...).

Reference if a path is defined (full or relative), the specified de_path will be ignored altogether.

Note:: The following discussions and conclusions are based on the following environment:
Suppose a =[Site]/APP/test/Main. phpAgain, we emphasize that the following discussion is about direct access to. ([Site] represents the root directory of the site, which can be replaced with a domain name root path such as the http://www.xxx.com or a physical directory such as: C: /wwwroot/xxx.com or/usr/wwwroot/xxx.com). Please create/APP/test/in the root directory of the website you can test/
Directory, and create main. php in it. It is best to practice all the examples below.

1.Relative Path:
The relative path requires a reference directory to determine the final path of the file. In the contained parsing, this reference directory is the directory where the program execution entry file is located, no matter how many layers are nested.

If
Define require in'./B. php'; // Then B =[Site]/APP/test/B. php

Define require in B'./C. php'; // C =[Site]/APP/test/C. phpNo
[Site]/APP/test/B/C. php

If
Define require in'./B. php'; // Then B =[Site]/APP/test/B. php

Define require in B'../C. php'; // C =[Site]/APP/C. phpNo
[Site]/APP/test/C. php

If
Define require in'../B. php'; // Then B =[Site]/APP/B. php

Define require in B'../C. php'; // C =[Site]/APP/C. phpNo
[Site]/C. php

If
Define require in'../B. php'; // Then B =[Site]/APP/B. php

Define require in B'./C. php'; // C =[Site]/APP/test/C. phpNo
[Site]/APP/C. php

If
Define require in'../INC/B. php'; // Then B =[Site]/APP/INC/B. php

Define require in B'./C. php'; // C or =[Site]/APP/test/C. phpNo
[Site]/APP/INC/C. php

Similarly, if
Define require in'../INC/B. php'; // Then B =[Site]/APP/INC/B. php

Define require in B'./C. php'; // C =[Site]/APP/test/C. phpNo
[Site]/APP/INC/C. php

2.Full path:
Full path is relatively simple, and it is not prone to confusion errors. A simple example
Define require in'/Wwwroot/xxx.com/app/test/ B .php'; // In windows, B =C:/wwwroot/xxx.com/app/test/ B .php
(C: The drive letter of the server). in Linux, B =/Wwwroot/xxx.com/app/test/ B .php

Dirname (_ file _) is also a full-path directory, but note that _ file _ is a magic constants, no matter when it is equal to the full path of the PHP file where the statement is written, dirname (_ file _) always points to the full path of the PHP file where the statement is written, it has nothing to do with whether the file is included or used by other files.

For example:
Define require in'../B. php'; // Then B =[Site]/APP/B. php

Define require in BDirname (_ file _). '/C. php'; // Then B =[Site]/APP/C. php

If
Define require in'../INC/B. php'; // Then B =[Site]/APP/INC/B. php

Define require in BDirname (_ file _). '/C. php'; // Then B =[Site]/APP/INC/C. phpAlways in the same directory as B

Conclusion: Whether B is used by a or accessed directly,
B. If require dirname (_ file _). '/C. php', always reference the c. php file in the same directory as B;
B. If require dirname (_ file _). '/../C. php', always reference the c. php file in the parent directory of file B;
B. If require dirname (_ file _). '/C. php', always reference the c. php file in the C subdirectory of the directory where file B is located;

3. In addition to relative paths and full pathsUncertain Path
First, use the include directory defined in include_path to concatenate [uncertain path]. If an existing file is found, the file is included and exited successfully. If not, the directory where the PHP file that writes the require statement is located is used to concatenate a full path consisting of [uncertain paths] to find the file. If the file exists, the file is successfully exited. Otherwise, the file does not exist and an error occurs.

The following discussion and conclusions need to call set_include_path (dirname (_ file _). '/../INC') at the beginning of file a; Set include_path
[Site]/APP/test/../INCDirectory is actually
[Site]/APP/INC

And define require 'in'../B. php'; // Fix B in[Site]/APP/B. php

In this case, if

 

Reference from: http://cuckoosnest.iteye.com/blog/479401

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.