Three ways to achieve page jump in PHP

There are three ways to achieve page jump in PHP. We introduce them one by one, and we recommend the first and third ways.

1. Realize with PHP's header() function.

The main function of the header() function is to output HTTP protocol headers to the browser.

note:

1. There can be no space between location and ":", otherwise it will not jump.

2. There can be no output before using the header.

3. The PHP code after the header will still be executed.

4. Some browsers have compatibility issues. For example, if the output byte of the IE browser is too small (less than 512 bytes), it will be ignored. Need to test multiple browsers in use.

<?php header("Location: http:// www.xxxx.com"); exit;//Prevent the execution of the code below and interrupt the execution//todo something

2. Realize with Meta tags

Meta tags are tags in HTML that are responsible for providing document meta information. If http-equiv is defined as refresh, when the page is opened, it will jump to the corresponding page within a certain time according to the value specified by content.

If you set content="seconds;url=URL", it defines how long the page will jump to the specified URL after elapsed.

E.g:

<?php //The page stays for one second and jumps to the specified link $url = "http://www.xxx.com"; echo "<meta http-equiv='refresh' content ='1;url=$url' >";

 

3. Realize with JavaScript

Just output the JavaScript code directly to the page.

<?php  $url = "http://www.xxx.com";  echo "<script language = 'javascript' type = 'text/javascript'>";echo "window.location.href = ".$url;echo "</script>";

 

Guess you like

Origin blog.csdn.net/hdl17822307857/article/details/112798416