PHP实现页面转的三种方式
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">PHP实现页面<span style="color: black;">转</span>有三种方式,<span style="color: black;">咱们</span>一一介绍,<span style="color: black;">举荐</span><span style="color: black;">运用</span>第<span style="color: black;">1、</span>三方式。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">1.借助PHP的header()函数实现。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">header()函数的<span style="color: black;">重点</span>功能是将HTTP协议标头(header)输出到浏览器。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">重视</span>:</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">1.location和":"号间<span style="color: black;">不可</span>有空格,否则不会<span style="color: black;">转</span>。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">2.在用header前<span style="color: black;">不可</span>有任何的输出。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">3.header后的PHP代码还会被执行。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">4.部分浏览器存在兼容性问题,例如:IE浏览器<span style="color: black;">倘若</span>输出的内容字节太小(<span style="color: black;">少于</span>512字节),<span style="color: black;">那样</span>就会被忽略。在<span style="color: black;">运用</span>时需要测试多个浏览器。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><?php</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">header("Location: http:// www.xxxx.com");</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">exit;//防止下方的代码执行,中断执行</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">//todo something</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">2.借助Meta标签实现</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">Meta标签是HTML中负责<span style="color: black;">供给</span>文档元信息的标签。若定义http-equiv为refresh,则打开该页面时将<span style="color: black;">按照</span>content规定的值在一<span style="color: black;">按时</span>间内<span style="color: black;">转</span>到相应页面。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">若设置content="秒数;url=网址",则定义了经<span style="color: black;">太多</span><span style="color: black;">长期</span>后页面<span style="color: black;">转</span>到指定的网址。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">例如:</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><?php</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">//页面停留一秒<span style="color: black;">转</span>至指定链接</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">$url = "http://www.xxx.com";</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">echo "<meta http-equiv=refresh content =1;url=$url>";</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">3.借助JavaScript实现</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">直接输出JavaScript代码至页面就行。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><?php</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">$url = "http://www.xxx.com";</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">echo "<script language = javascript type = text/javascript>";</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">echo "window.location.href = ".$url;</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">echo "</script>";</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">————————————————</p>
页:
[1]