Home > Backend Development > PHP Tutorial > Discuss several implementation techniques for PHP page jump_PHP tutorial

Discuss several implementation techniques for PHP page jump_PHP tutorial

WBOY
Release: 2016-07-15 13:35:01
Original
939 people have browsed it

In the Web system, jumping from one web page to another web page is one of the most commonly used technologies in the LAMP project. Page jumps may be caused by users clicking links, buttons, etc., or they may be automatically generated by the system. Here we introduce the methods commonly used in PHP to realize automatic page jump.

PHP page jump 1. header() function

The header() function is a very simple method for page jump 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 the replacement before A similar header or add a header of the same type, the default is to replace.

The second optional parameter http_response_code forces the HTTP response 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: 1. There cannot be a space between location and ":", otherwise it will not jump.

2. There cannot be any output before using the header.

3. The PHP code after the header will also be executed. For example, redirect the browser to the official forum of Lamp Brothers

<ol class="dp-xml"><li class="alt"><span><span class="tag"><</span><span> ?php </span></span></li><li class="alt"><span><span>//重定向浏览器 </span></span></li><li class="alt"><span><span>header("Location: http://bbs.<br />lampbrother.net"); </span></span></li><li class="alt"><span><span>//确保重定向后,后续代码不会被执行 </span></span></li><li class="alt"><span><span>exit;</span></span></li><li class="alt"><span><span class="tag">?></span><span>  </span></span></li></ol>
Copy after login

PHP page jump 2. Meta tag

Meta tag is responsible for providing document elements in HTML Information tag, using this tag in PHP program can also realize page jump. If http-equiv is defined as refresh, when the page is opened, it will jump to the corresponding page within a certain period of time based on the value specified by content.

If content="seconds;url=website" is set, it defines how long it will take for the page to jump to the specified URL. For example, the meta tag is used to automatically jump to the LAMP Brothers Band official forum after the vaccine is released.

<ol class="dp-xml"><li class="alt"><span><span class="tag"><</span><span> </span><span class="tag-name">meta</span><span> </span><span class="attribute">http-equiv</span><span>=</span><span class="attribute-value">"refresh"</span><span> </span></span></li><li class="alt"><span><span class="attribute">content</span><span>=</span><span class="attribute-value">"1;url=http://<br />bbs.lampbrother.net"</span><span class="tag">></span><span> </span></span></li></ol>
Copy after login

For example, the following program meta.php implements the page to automatically jump to bbs.lampbrother.net after staying on the page for one second.

<ol class="dp-xml">
<li class="alt"><span><span class="tag"><</span><span> ?php   </span></span></li><li><span>$</span><span class="attribute">url</span><span> = </span><span class="attribute-value">"http://bbs.lampbrother.net"</span><span>; </span><span class="tag">?></span><span> </span></span></li>
<li class="alt">
<span class="tag"><</span><span> </span><span class="tag-name">html</span><span class="tag">></span><span>   </span>
</li>
<li>
<span class="tag"><</span><span> </span><span class="tag-name">head</span><span class="tag">></span><span>   </span>
</li>
<li class="alt">
<span class="tag"><</span><span> </span><span class="tag-name">meta</span><span> </span><span class="attribute">http-equiv</span><span>=</span><span class="attribute-value">"refresh"</span><span> </span><span class="attribute">content</span><span>="1;  </span></li><li><span class="attribute">url</span><span>=</span><span class="tag"><</span><span> ?php echo $url; </span><span class="tag">?></span><span>"</span><span class="tag">></span><span>   </span>
</li>
<li class="alt">
<span class="tag"><</span><span> /head</span><span class="tag">></span><span>   </span>
</li>
<li>
<span class="tag"><</span><span> </span><span class="tag-name">body</span><span class="tag">></span><span>   </span>
</li>
<li class="alt"><span>页面只停留一秒……   </span></li>
<li>
<span class="tag"><</span><span> /body</span><span class="tag">></span><span> </span>
</li>
<li class="alt">
<span class="tag"><</span><span> /html</span><span class="tag">></span><span>  </span>
</li>
</ol>
Copy after login

PHP page jump 3. JavaScript

For example, this code can be placed in any legal position in the program.

<ol class="dp-xml">
<li class="alt"><span><span class="tag"><</span><span> ?php  </span></span></li><li><span>$</span><span class="attribute">url</span><span> = </span><span class="attribute-value">"http://bbs.lampbrother.net"</span><span>;  </span></li><li class="alt"><span>echo "</span><span class="tag"><</span><span> </span><span class="tag-name">script</span><span> </span><span class="attribute">language</span><span>=</span><span class="attribute-value">'javascript'</span><span> </span></li><li class="alt"><span class="attribute">type</span><span>=</span><span class="attribute-value">'text/javascript'</span><span class="tag">></span><span>";  </span></span></li>
<li>
<span>echo "</span><span class="attribute">window.location.href</span><span>=</span><span class="attribute-value">'$url'</span><span>";  </span>
</li>
<li class="alt">
<span>echo "</span><span class="tag"><</span><span> /script</span><span class="tag">></span><span>";  </span>
</li>
<li>
<span class="tag">?></span><span> </span>
</li>
</ol>
Copy after login

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


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445935.htmlTechArticleIn the Web system, jumping from one web page to another web page is one of the most commonly used technologies in the LAMP project . Page jumps may be caused by users clicking links, buttons, etc., or they may be caused by...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template