Heim > Backend-Entwicklung > PHP-Tutorial > PHP函数header()查询单部件的具体方法解析_PHP教程

PHP函数header()查询单部件的具体方法解析_PHP教程

WBOY
Freigeben: 2016-07-15 13:29:26
Original
967 Leute haben es durchsucht

我们今天为大家讲解的具体内容时如何运用下面是一个叫做 calling.php 的脚本:

<ol class="dp-xml">
<li class="alt"><span><span>nbsp;HTML PUBLIC   </span></span></li>
<li class=""><span>"-//W3C//DTD HTML 4.0 Transitional//EN"   </span></li>
<li class="alt">
<span>"http://www.w3.org/TR/html4/loose.dtd" </span><span class="tag"><strong><font color="#006699">></font></strong></span><span>   </span>
</li>
<li class="">
<span></span><strong><font color="#006699"><span class="tag"><span class="tag-name">html</span><span class="tag">></span></span></font></strong><span>   </span>
</li>
<li class="alt">
<span></span><strong><font color="#006699"><span class="tag"><span class="tag-name">head</span><span class="tag">></span></span></font></strong><span>   </span>
</li>
<li class="">
<span></span><strong><font color="#006699"><span class="tag"><span class="tag-name">title</span><span class="tag">></span></span></font></strong><span>Calling page example</span><strong><font color="#006699"><span class="tag"></span><span class="tag-name">title</span><span class="tag">></span></font></strong><span>   </span>
</li>
<li class="alt">
<span></span><strong><font color="#006699"><span class="tag"></span><span class="tag-name">head</span><span class="tag">></span></font></strong><span>   </span>
</li>
<li class="">
<span></span><strong><font color="#006699"><span class="tag"><span class="tag-name">body</span><span class="tag">></span></span></font></strong><span>   </span>
</li>
<li class="alt">
<span></span><strong><font color="#006699"><span class="tag"><span class="tag-name">a</span></span></font></strong><span> </span><span class="attribute"><font color="#ff0000">href</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">"action.php"</font></span><span class="tag"><strong><font color="#006699">></font></strong></span><span>Click here!</span><strong><font color="#006699"><span class="tag"></span><span class="tag-name">a</span><span class="tag">></span></font></strong><span>   </span>
</li>
<li class="">
<span></span><strong><font color="#006699"><span class="tag"></span><span class="tag-name">body</span><span class="tag">></span></font></strong><span>   </span>
</li>
<li class="alt">
<span></span><strong><font color="#006699"><span class="tag"></span><span class="tag-name">html</span><span class="tag">></span></font></strong><span>   </span>
</li>
</ol>
Nach dem Login kopieren

当用户点击上面的连接时,PHP函数header()就去调用 action.php。下面是 action.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></li>
<li class="alt"><span> </span></li>
<li class=""><span>// 重定向   </span></li>
<li class="alt"><span>header("Location: $HTTP_REFERER");   </span></li>
<li class=""><span>exit;   </span></li>
<li class="alt">
<span></span><span class="tag"><strong><font color="#006699">?></font></strong></span><span>   </span>
</li>
</ol>
Nach dem Login kopieren

这里有两个常见的错误需要提醒一下:

调用PHP函数header()后要包含一个 exit 语句让脚本停止,否则后续的脚本可能会在头发送前输出。

header() 函数常见的一个错误是:

Warning: Cannot add header information - headers already sent...

PHP函数header()只能在 HTML 输出之前被调用,因此你需要检查 php 前面可能存在的空行,空格等等。


www.bkjia.comtruehttp://www.bkjia.com/PHPjc/446369.htmlTechArticle我们今天为大家讲解的具体内容时如何运用 下面是一个叫做 calling.php 的脚本: !DOCTYPEHTMLPUBLIC "-//W3C//DTDHTML4.0Transitional//EN" "http://www.w3.org/...
Quelle:php.cn
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
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage