Article From:https://www.cnblogs.com/Im-Victor/p/9277985.html

PHPPage jump one, header () function

header()Function is a very simple way to page Jump in PHP. The main function of the header () function is to export the HTTP protocol header (header) to the browser.

header()The definition of the function is as follows:

void header (string string [,bool replace [,int http_response_code]])

Optional parameter replace specifies whether to replace a 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 HTTP corresponding code to be set to the specified value. The header of type Location in header function is a special header call, which is commonly used to implement page jumping. Note: 1.locatThere is no space between ion and “:”, otherwise it will not jump.

2.You can’t have any output before using header.

3.headerThe later PHP code will be executed. for example

 

[php] view plaincopyprint?

 
  1. < ?php   
  2. //Redirection browsers
  3. header(“Location: http://blog.csdn.net/abandonship”);   
  4. //Ensure that the reset is backward and subsequent code will not be executed.
  5. exit;  
  6. ?>    

 

 

PHPPage jump two, Meta tag

MetaTags are tags that are responsible for providing document meta information in HTML, which can also be used in PHP programs. If http-equiv is defined as refresh, when it 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= address”, you define how long after the page skips to the specified URL.

meta http-equiv=“refresh” content=“1;url=http://blog.csdn.net/abandonship”

For example, the following program meta.php implements the page skipping automatically after one second in the page.

 

[php] view plaincopyprint?

 
  1. <?php     
  2. $url = “http://blog.csdn.net/abandonship”;   
  3. ?>   
  4. <html>     
  5. <head>     
  6. <meta http-equiv=“refresh” content=“1;url=<?php echo $url; ?>”>     
  7. </head>     
  8. <body>   
  9. It’s transit station.  
  10. </body>  
  11. </html>  

 

 

PHPPage jump three, JavaScript

 

[php] view plaincopyprint?

 
  1. <?php    
  2. $url = “http://blog.csdn.net/abandonship”;  
  3. echo “<script type=’text/javascript’>”;  
  4. echo “window.location.href=’$url'”;  
  5. echo “</script>”;   
  6. ?>   

Leave a Reply

Your email address will not be published. Required fields are marked *