>백엔드 개발 >PHP 튜토리얼 >PHP函数header()查询单部件的具体方法解析_PHP教程

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

WBOY
WBOY원래의
2016-07-15 13:29:26973검색

我们今天为大家讲解的具体内容时如何运用下面是一个叫做 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>

当用户点击上面的连接时,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>

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

调用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/...
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.