Heim > Backend-Entwicklung > PHP-Tutorial > PHP重定向的具体实现方式_PHP教程

PHP重定向的具体实现方式_PHP教程

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Freigeben: 2016-07-15 13:28:45
Original
831 Leute haben es durchsucht

一、用HTTP头信息

也就是用PHP的HEADER函数。PHP里的HEADER函数的作用就是向浏览器发出由HTTP协议规定的本来应该通过WEB服务器的控制指令,例如声明返回信息的类型("Context-type: xxx/xxx"),页面的属性("No cache", "Expire")等等。

用HTTP头信息进行PHP重定向到另外一个页面的方法如下:

<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>
<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>
</li>
<li class="alt"><span>if (!empty($url))    </span></li>
<li class=""><span>{    </span></li>
<li class="alt"><span>    Header("HTTP/1.1 303 See Other"); //这条语句可以不写  </span></li>
<li class=""><span>    Header("Location: $url");  </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>
Nach dem Login kopieren

注意一下,"Localtion:"后面有一个空格。

二、用HTML标记PHP重定向 

用HTML标记,就是用META的REFRESH标记,举例如下:

<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>
<li class=""><span>if (!empty($url))  </span></li>
<li class="alt"><span>{  </span></li>
<li class="">
<span>    echo "</span><strong><font color="#006699"><span class="tag"><span class="tag-name">META</span></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">></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>
Nach dem Login kopieren

三、用脚本来实现PHP重定向

举例如下:

<ol class="dp-xml">
<li class="alt"><span><span class="tag"><strong><font color="#006699"></font></strong></span><span> </span></span></li>
<li class="">
<span></span><span class="tag-name"><strong><font color="#006699">if</font></strong></span><span> (isset($url))  </span>
</li>
<li class="alt"><span>{  </span></li>
<li class="">
<span>    echo "</span><strong><font color="#006699"><span class="tag"><span class="tag-name">SCRIPT</span></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>
</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>
Nach dem Login kopieren
或者

<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 class="tag-name">script</span><span class="tag">></span></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>
Nach dem Login kopieren


www.bkjia.comtruehttp://www.bkjia.com/PHPjc/446419.htmlTechArticle一、用HTTP头信息 也就是用PHP的HEADER函数。PHP里的HEADER函数的作用就是向浏览器发出由HTTP协议规定的本来应该通过WEB服务器的控制指令,例...
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Aktuelle Ausgaben
PHP-Datenerfassung?
Aus 1970-01-01 08:00:00
0
0
0
PHP-Erweiterung intl
Aus 1970-01-01 08:00:00
0
0
0
Wie man PHP gut lernt
Aus 1970-01-01 08:00:00
0
0
0
Mehrere PHP-Versionen
Aus 1970-01-01 08:00:00
0
0
0
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage