Several implementation methods of PHP jump page in detail

  • 2020-06-12 08:37:16
  • OfStack

The & # 8226; PHP page jump 1. header() function
The header() function is a simple 10-point method of page hopping in PHP. The main function of the header() function is to output the HTTP protocol header (header) to the browser.
The header() function is defined as follows:
void header (string string [,bool replace [,int http_response_code]])
The optional parameter replace indicates whether to replace the previous similar header or to add a header of the same type, which is replaced by default.
The second optional parameter, http_response_code, forces the corresponding code of HTTP to be set to the specified value. The Location header in the header function is a special header call that is often used for page jumping.
1. There should be no space between location and ":", otherwise it will not jump.
2. No output before using header.
3. PHP code after header will be executed. For example, redirect the browser to the lamp brothers official forum

<  ?php 
// Redirect browser  
header("Location: http://bbs."); 
// Make sure that subsequent code is not executed after the redirect  

The & # 8226; PHP page jump 2. Meta TAB
The Meta tag is the tag in HTML that is responsible for providing document meta-information. It is also used in PHP programs to enable page jumping. If http-ES41en is defined as refresh, the page will jump to the corresponding page within 1 fixed time according to the value specified by content.
Set content=" number of seconds; url= url "defines how long it takes for the page to jump to the specified url. For example, after using the meta tag to implement the vaccine, the page automatically redirects to the official forum of the LAMP Brotherhood.

<   meta   http-equiv = "refresh"  
content = "1;url=http://" >

For example, the following program meta.php implements the automatic jump to after staying on the page for 1 second.

<  ?php   
$ url  =  "" ;  ?>  
<   html >    
<   head >    
<   meta   http-equiv = "refresh"   content ="1;  
url = <  ?php echo $url;  ?> " >    
<  /head >    
<   body >    
 Page stays only 1 Seconds...    
<  /body >  
<  /html >

PHP page jump 3. JavaScript
For example, this code can be placed anywhere in the program that is legal.

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

These are the three PHP page jump implementation methods we introduced to you.

Related articles: