Home  >  Article  >  Backend Development  >  The specific implementation method of PHP redirection_PHP tutorial

The specific implementation method of PHP redirection_PHP tutorial

WBOY
WBOYOriginal
2016-07-15 13:28:45781browse

1. Use HTTP header information

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: xxx/xxx"), the attributes of the page ("No cache", "Expire"), etc.

The method of using HTTP header information to redirect PHP to another page is as follows:

<ol class="dp-xml"><li class="alt">
<span><strong><font color="#006699"><span class="tag"><?</SPAN><SPAN class=tag-name>php</SPAN></FONT></STRONG><SPAN> </SPAN></SPAN><LI class=""><SPAN>$</SPAN><SPAN class=attribute><FONT color=#ff0000>url</FONT></SPAN><SPAN> = </SPAN><SPAN class=attribute-value><FONT color=#0000ff>"www.baidu.com"</FONT></SPAN><SPAN>;  </SPAN></SPAN><LI class=alt><SPAN>if (!empty($url))    </SPAN><LI class=""><SPAN>{    </SPAN><LI class=alt><SPAN>    Header("HTTP/1.1 303 See Other"); //这条语句可以不写  </SPAN><LI class=""><SPAN>    Header("Location: $url");  </SPAN><LI class=alt><SPAN>}    </SPAN><LI class=""><SPAN></SPAN><SPAN class=tag><STRONG><FONT color=#006699>?></span></font></strong></span><span>    </span>
</li></ol>

Note that there is a following "Localtion:" Space.

2. Use HTML to mark PHP redirection

Mark it with HTML, that is, use the META REFRESH tag, for example:

<ol class="dp-xml">
<li class="alt">
<span><strong><font color="#006699"><span class="tag"><?</SPAN><SPAN class=tag-name>php</SPAN></FONT></STRONG><SPAN> </SPAN></SPAN><LI class=""><SPAN>if (!empty($url))  </SPAN><LI class=alt><SPAN>{  </SPAN><LI class=""><SPAN>    echo "</SPAN><STRONG><FONT color=#006699><SPAN class=tag><</SPAN><SPAN class=tag-name>META</SPAN></FONT></STRONG><SPAN> </SPAN><SPAN class=attribute><FONT color=#ff0000>HTTP-EQUIV</FONT></SPAN><SPAN>="Refresh" </SPAN><SPAN class=attribute><FONT color=#ff0000>CONTENT</FONT></SPAN><SPAN>="0;</SPAN><SPAN class=attribute><FONT color=#ff0000>URL</FONT></SPAN><SPAN>=$url"</SPAN><SPAN class=tag><STRONG><FONT color=#006699>></span></font></strong></span><span>";  </span>
</li>
<li class="alt"><span>}  </span></li>
<li class="">
<span></span><span class="tag"><strong><font color="#006699">?></font></strong></span><span> </span>
</li>
</ol>

3. Use scripts to implement PHP redirection

For example:

<ol class="dp-xml">
<li class="alt"><span><span class="tag"><strong><font color="#006699"><?</FONT></STRONG></SPAN><SPAN> </SPAN></SPAN><LI class=""><SPAN></SPAN><SPAN class=tag-name><STRONG><FONT color=#006699>if</FONT></STRONG></SPAN><SPAN> (isset($url))  </SPAN></SPAN><LI class=alt><SPAN>{  </SPAN><LI class=""><SPAN>    echo "</SPAN><STRONG><FONT color=#006699><SPAN class=tag><</SPAN><SPAN class=tag-name>SCRIPT</SPAN></FONT></STRONG><SPAN> </SPAN><SPAN class=attribute><FONT color=#ff0000>LANGUAGE</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>"JavaScript"</FONT></SPAN><SPAN class=tag><STRONG><FONT color=#006699>></font></strong></span><span>";  </span></span></li>
<li class="alt">
<span>    echo "</span><span class="attribute"><font color="#ff0000">location.href</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">'$url'</font></span><span>";  </span>
</li>
<li class="">
<span>    echo "</span><strong><font color="#006699"><span class="tag"></</SPAN><SPAN class=tag-name>SCRIPT</SPAN><SPAN class=tag>></span></font></strong><span>";  </span>
</li>
<li class="alt"><span>}  </span></li>
<li class="">
<span></span><span class="tag"><strong><font color="#006699">?></font></strong></span><span> </span>
</li>
</ol>
or

<ol class="dp-xml"><li class="alt"><span><strong><font color="#006699"><span class="tag"><?</SPAN><SPAN class=tag-name>php</SPAN></FONT></STRONG><SPAN> echo "</SPAN><STRONG><FONT color=#006699><SPAN class=tag><</SPAN><SPAN class=tag-name>script</SPAN><SPAN class=tag>></span></font></strong><span class="attribute"><font color="#ff0000">window.location</font></span><span> ="$url";</span><strong><font color="#006699"><span class="tag"></</SPAN><SPAN class=tag-name>script</SPAN><SPAN class=tag>></span></font></strong><span>";</span><span class="tag"><strong><font color="#006699">?></font></strong></span><span> </span></span></li></ol>


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446419.htmlTechArticle1. Use HTTP header information, 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 as specified by the HTTP protocol, for example...
Statement:
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