PHPの页面跳转-常见方法,phpの页面跳转
PHPの页面跳转-常见方法,phpの页面跳转
PHP页面跳转一、header()函数
header()函数是PHP中进行页面跳转的一种十分简单的方法。header()函数的主要功能是将HTTP协议标头(header)输出到浏览器。
header()函数的定义如下:
<p>void header (string string [,bool replace [,int http_response_code]])</p>
可选参数replace指明是替换前一条类似标头还是添加一条相同类型的标头,默认为替换。
第二个可选参数http_response_code强制将HTTP相应代码设为指定值。 header函数中Location类型的标头是一种特殊的header调用,常用来实现页面跳转。注意:1.location和“:”号间不能有空格,否则不会跳转。
2.在用header前不能有任何的输出。
3.header后的PHP代码还会被执行。例如,将浏览器重定向到冠威博客
<p>< ?php<br />//重定向浏览器<br />header("Location: http://www.guanwei.org");<br />//确保重定向后,后续代码不会被执行<br />exit;<br />?></p>
PHP页面跳转二、Meta标签
Meta标签是HTML中负责提供文档元信息的标签,在PHP程序中使用该标签,也可以实现页面跳转。 若定义http-equiv为refresh,则打开该页面时将根据content规定的值在一定时间内跳转到相应页面。
若设置content="秒数;url=网址",则定义了经过多长时间后页面跳转到指定的网址。例如,使用meta标签实现疫苗后页面自动跳转到冠威博客。
<p>< meta http-equiv="refresh" content="1;url=http://www.guanwei.org"></p>
例如,以下程序meta.php实现在该页面中停留一秒后页面自动跳转到www.guanwei.org。
<p>< ?php<br />$url = "http://www.guanwei.org"; ?><br />< html><br />< head><br />< meta http-equiv="refresh" content="1; url=< ?php echo $url; ?>"><br />< /head><br />< body><br />页面只停留一秒……<br />< /body><br />< /html></p>
PHP页面跳转三、JavaScript(常用、推荐)
例如,此代码可以放在程序中的任何合法位置。
<p>< ?php<br />$url = "http://www.guanwei.org";<br />echo "<script language='javascript' type='text/javascript'>";<br />echo "window.location.href='$url'";<br />echo "</script>";<br />?></p>
使用php去跳转的话并不方便,大多数用js来实现跳转
如:
echo "<script>location.href='t.php';</script>"; // 跳转到 t.php<br /> <br />这个方法比较常用<br/>
<p class="header2"><span class="icon i-relatedanswer"><h3>Linux综合指导:php实现页面跳转的几种方法</script>
在实际开发中,网站的各项功能都可以通过PHP语言的编写来满足,比如PHP页面跳转这一方法。 探讨PHP变量解析顺序如何获取提交数据 深入解读PHP运行机制 浅析PHP函数extract()应用技巧 为你总结一些PHP信息函数 PHP查询字符串技巧分享 Web系统中,从一个网页跳转到另一个网页,是LAMP项目中最常用的技术之一。页面跳转可能是由于用户单击链接、按钮等引发的,也可能是系统自动产生的。 此处介绍PHP中常用的实现页面自动跳转的方法。 PHP页面跳转一、header()函数 header()函数是PHP中进行页面跳转的一种十分简单的方法。header()函数的主要功能是将HTTP协议标头(header)输出到浏览器。 header()函数的定义如下: void header (string string [,bool replace [,int http_response_code]]) 可选参数replace指明是替换前一条类似标头还是添加一条相同类型的标头,默认为替换。 第二个可选参数http_response_code强制将HTTP相应代码设为指定值。 header函数中Location类型的标头是一种特殊的header调用,常用来实现页面跳转。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

Validator can be created by adding the following two lines in the controller.
