Home >Backend Development >PHP Problem >How to jump to html from php
How to jump from php to html: You can choose to use the header() function to jump, such as [header("Location: http://www.xxxxx.com");]. It should be noted that there cannot be any output before the header() function.
The method is as follows:
(Video tutorial recommendation: php video tutorial)
1. header() function jump
void header(String String[,bool replace[,int http_response_code]]);
The optional parameter replace specifies whether to replace the previous similar header or add a header of the same type. The default is replacement.
The second optional parameter http_response_code forces the HTTP corresponding code to the specified value. The Location type header in the header function is a special header call, often used to implement page jumps.
Note: There cannot be a space between
location and the ":" sign, otherwise it will not jump.
There cannot be any output before using the header.
The PHP code after the header will also be executed.
Example:
< ?php //重定向地址 header("Location: http://www.xxxxx.com"); //运用exit进行退出确保重定向后,后续代码不会被执行 exit; ?>
2. Use javascript jump method
< ?php $url = http://www.xxxxx.com; echo "<script language='javascript' type='text/javascript'>"; echo "window.location.href='$url'"; echo "</script>"; ?>
Related recommendations: php training
The above is the detailed content of How to jump to html from php. For more information, please follow other related articles on the PHP Chinese website!