Home  >  Article  >  Backend Development  >  How to jump to html from php

How to jump to html from php

王林
王林Original
2020-11-02 11:00:447691browse

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.

How to jump to html from php

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=&#39;javascript&#39; type=&#39;text/javascript&#39;>";
echo "window.location.href=&#39;$url&#39;";
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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn