The PHP server jump code is "function server_transfer($dest) global ...;include $dest;exit;". This method can jump between PHP server pages.
The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer
What is the php server jump code?
PHP server page jump implementation method
In ASP, we can use Server.Transfer to achieve server-side redirection, although in PHP There is no such function, but it is not difficult to achieve a similar jump
(Note that it is not a client-side jump made by header, js, etc.)
Code As follows:
function server_transfer($dest) { global ...; // 把希望在新页面中用到的本页变量或者自定义的全局变量列在这里 include $dest; // 运行新脚本 exit; // 退出本脚本 }
Note:
1. If any data output before the jump will be displayed in the new page, unless the ob_start buffer is used, it can be cleared before the jump, so that there is no mutual Affected.
2. Since the new page runs within a custom function scope, the variables defined on this page will not affect the new page, which is both a benefit and a disadvantage.
3. New pages can still use super-global variables such as $_POST to access variables that originally belong to this page. You need to pay attention when writing code.
4. Consider the problem of duplicate inclusion of this page and the new page. If Both pages contain the same page, such as headers and footers, and require_once is used.
In short, the jump can be done, but the programmer must know what is happening, otherwise it is easy to get some strange Result.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What is the php server jump code?. For more information, please follow other related articles on the PHP Chinese website!