php页面跳转的几种方式

@: PHP页面跳转的三种方式

第一种方式:header()

header()函数的主要功能是将HTTP协议标头(header)输出到浏览器。

语法:

void header ( string $string [, bool $replace = true [, int $http_response_code ]] )

可选参数replace指明是替换前一条类似标头还是添加一条相同类型的标头,默认为替换。

第二个可选参数http_response_code强制将HTTP相应代码设为指定值。 header函数中Location类型的标头是一种特殊的header调用,常用来实现页面跳转。注意:1.location和“:”号间不能有空格,否则不会跳转。

举例:

<html>
<?php
/* This will give an error. Note the output
 * above, which is before the header() call */
header(‘Location: http://www.example.com/‘);
exit;
?>

注意:

- header执行前不能有任何输出

- location和:之间不能有空格

- header后的php代码还会执行,所以需要注意使用exit;

第二种方式:meta标签

Meta标签是HTML中负责提供文档元信息的标签,在PHP程序中使用该标签,也可以实现页面跳转。 若定义http-equiv为refresh,则打开该页面时将根据content规定的值在一定时间内跳转到相应页面。

< meta http-equiv="refresh"
content="1;url=http://
www.baidu.com">

第三种方式:javascript

通过使用windows.location.href=‘url’; 是页面自动跳转到新的地址

< ?php
$url = "http://www.baidu.com";
echo "< script language=‘javascript‘
type=‘text/javascript‘>";
echo "window.location.href=‘$url‘";
echo "< /script>";
?> 

第四种方式:form表单

通过php加载一个html页面,html页面中隐藏一个form表单,再写个js在页面加载时自动提交form表单达成跳转

<html>
<head>
    <meta charset="utf-8">
</head>
<body onload="load()">
<form id="formCommit" action="http://www.baidu.com" method="post">
<input type="hidden" id = "req" name="req" value="<?php echo htmlspecialchars($param[‘resp‘]);?>" />
<input type="hidden" id = "sign" name="sign" value="<?php echo htmlspecialchars($param[‘sign‘]);?>" />
</form>
<script type="text/javascript">
function load(){
   document.getElementById("formCommit").submit();
}
</script>
</body>
</html>
时间: 2024-08-04 01:35:19

php页面跳转的几种方式的相关文章

JavaScript实现页面跳转的五种方式

JavaScript实现页面跳转的五种方式 第一种:<script type="text/javascript" language="javascript"> window.location.href="login.jsp?backurl="+window.location.href;</script> 第二种:<script type="text/javascript" language=&qu

实现前端页面跳转的几种方式

实现前端页面跳转的几种方式 推荐使用 <script language='javascript'> document.location = 'http://mail.qq.com/domain/longtimenosee.cc' </script> 相关阅读 http://www.jb51.net/article/25403.htm http://my.oschina.net/ososchina/blog/340854

web项目中实现页面跳转的两种方式

<a href="javascript:"></a>跳转在网页本身,URL不改变 <a href="#"></a> 跳转在网页本身,URL 改变 java web项目中实现页面跳转的主要方式有两种:第一种,<% response.sendRedirect("index.jsp");%>第二种<jsp:forward page="index.jsp"/>我做

php中实现页面跳转的几种方式

亲测,not复制粘贴 PHP中实现页面跳转有一下几种方式,看了几个人写的不是很条理,自己整理一下 在PHP脚本代码中实现 <?php header("location:url地址") ?> 例如 <?php header("location:helloworld.php")?> 页面会立即跳转,因为header执行了location重定向 延迟跳转(比如登陆成功后会有几秒钟等待时间,然后跳转到了其他页面) <?php header(&q

PHP 页面跳转的三种方式

第一种方式:header() header()函数的主要功能是将HTTP协议标头(header)输出到浏览器. 语法: void header ( string $string [, bool $replace = true [, int $http_response_code ]] ) 可选参数replace指明是替换前一条类似标头还是添加一条相同类型的标头,默认为替换. 第二个可选参数http_response_code强制将HTTP相应代码设为指定值. header函数中Location类

用js实现页面跳转的几种方式

通过js或者html或者PHP等动态程序都可以方便的实现跳转,这里搜集了几种页面跳转的方式 js方式的页面跳转 1.window.location.href方式 <script language="JavaScript" type="text/javascript"> window.location.href="http://www.dayanmei.com/"; </script> 2.window.navigate方式

页面跳转的几种方式

第一种: <script language="javascript"> window.location.href="index.php"; //比较常用的方法,没什么可解释的,后面直接跟指定要跳转的地方. </script> 第二种: <script language="javascript"> alert("返回"); window.history.back(-1); //类似于按钮,参数

js实现页面跳转的两种方式

CreateTime--2017年8月24日08:13:52Author:Marydon 方式一: window.location.href = url 说明:我们常用来在js中实现页面跳转的方法,使用get方式发送请求,传参有限 更多介绍,见文章:js操作当前窗口 方式二: 通过POST请求实现页面跳转 /** * 发送POST请求跳转到指定页面 * @param URL * 跳转路径 * @param PARAMS * 参数:格式-JSON对象 */ function httpPost(UR

js实现页面跳转的几种方式

第一种: <script language="javascript" type="text/javascript"> window.location.href="xx.jsp?backurl="+window.location.href; </script> 另外一种: <script language="javascript"> alert("返回"); window.