Home >Backend Development >PHP Tutorial >Explain in detail the specific meaning of PHP page jump function_PHP Tutorial
For
PHP itself does not have a complete PHP page jump function. Maybe the Header function is one, but it can only be used for the first page of the page. OK. If placed at the end of the PHP page, unless the previous PHP does not output any characters, an error will be reported.
The following are three methods for automatic page jump in PHP. One is to use the Header function, and the other is to use HTML inherent tags. Of course, this method can not only be applied to PHP, but also to ASP. , .Net, and Jsp, the third method is to output Javascript and use Js code to achieve the purpose of automatic jump to the PHP page. Similarly, this method is also applicable to other languages other than PHP, but the corresponding language codes are different. That’s all.
PHP page jump function 1. Use HTTP header information (Header function)
That is, use PHP’s HEADER function. The function of the HEADER function in PHP is to issue control instructions to the browser that should be passed through the WEB server specified by the HTTP protocol, such as declaring the type of return information ("Context-type: xxxx/xxxx"), the attributes of the page ("No cache", "Expire"), etc.
The method to use HTTP header information to automatically jump to another page in PHP is as follows:
<ol class="dp-xml"><li class="alt"> <span class="tag"><</span> ?PHP </li><li><span>$</span><span class="attribute">url</span><span> = </span><span class="attribute-value">czbin</span><span>.</span>PHP<span> </span></li><li class="alt"><span>Header("HTTP/1.1 303 See Other"); </span></li><li><span>Header("Location: $url"); </span></li><li class="alt"><span>exit; </span></li><li><span class="tag">?></span><span> </span> </li></ol>
Note that there is a space after "Localtion:".
PHP page jump function 2. Use HTML tag (REFRESH attribute in META)
Use HTML tag, that is, use META's REFRESH tag, for example:
<ol class="dp-xml"> <li class="alt"><span class="tag"><</span> ?PHP<span> $</span><span class="attribute">url</span><span> = </span><span class="attribute-value">czbin</span><span>.</span>PHP<span>;</span><span>?> </span></li> <li> <span class="tag"><</span><span> </span><span class="tag-name">HTML</span><span class="tag">></span><span> </span> </li> <li class="alt"> <span class="tag"><</span><span> </span><span class="tag-name">HEAD</span><span class="tag">></span><span> </span> </li> <li> <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> <br /></span><span class="attribute">CONTENT</span><span>="10; </span><span class="attribute">URL</span><span>=</span><span class="tag"><</span><span> ? echo $url;</span><span class="tag">?></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 class="tag"><</span><span> /BODY</span><span class="tag">></span><span> </span> </li> <li> <span class="tag"><</span><span> /HTML</span><span class="tag">></span><span> </span> </li> </ol>
Note: CONTENT="10 here means to jump after 10 seconds.
PHP page jump function Number three, use JAVASCRIPT script to implement
as follows:
<ol class="dp-xml"> <li class="alt"><span><span class="tag">< ?</span></span>PHP<span><span> </span></span></li><li><span>$</span><span class="attribute">url</span><span>=</span><span class="attribute-value">czbin</span><span>.</span>PHP<span>; </span></li><li class="alt"><span>echo "< !--</span><span class="tag">< </span><span class="tag-name">SCRIPT</span><span> </span><span class="attribute">LANGUAGE</span><span>=</span><span class="attribute-value">"JavaScript"</span><span class="tag">></span><span>"; </span></span></li> <li> <span>echo "</span><span class="attribute">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 class="tag-name">SCRIPT</span><span class="tag">></span><span>--</span><span class="tag">></span><span>"; </span> </li> <li> <span class="tag">?></span><span> </span> </li> </ol>