教程集 www.jiaochengji.com
教程集 >  脚本编程  >  php  >  正文 php页面跳转另一页面各种跳转页面代码

php页面跳转另一页面各种跳转页面代码

发布时间:2016-12-03   编辑:jiaochengji.com
教程集为您提供php页面跳转另一页面各种跳转页面代码等资源,欢迎您收藏本站,我们将为您提供最新的php页面跳转另一页面各种跳转页面代码资源
在php中实现页面跳转的方法只有一种,就是使用header(location:$go_url); 就可以实现了页面跳转了,下面我来给各位同学详细介绍介绍。

php header()页面跳转

我把blog从http://www.你的域名/blog迁移到http://www.jiaochengji.com域名下,当用户访问以前blog地址时,自动跳转到当前blog的对应文章

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy1257')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy1257>

$url_this=strtolower('http://'.$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]); 
$go_url=str_replace('http://www.你的域名/blog','http://www.jiaochengji.com',$url_this); 
header("location:$go_url");  exit;


header()函数的定义如下:

void header (string string [,bool replace [,int http_response_code]])
可选参数replace指明是替换前一条类似标头还是添加一条相同类型的标头,默认为替换。
第二个可选参数http_response_code强制将HTTP相应代码设为指定值。 header函数中Location类型的标头是一种特殊的header调用,常用来实现页面跳转。

注意:

1.location和“:”号间不能有空格,否则不会跳转。
2.在用header前不能有任何的输出。
3.header后的PHP代码还会被执行。

还有一种js php页面跳转方法

JavaScript(常用、推荐)

例如,此代码可以放在程序中的任何合法位置。

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy1687')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy1687>

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

1. HTML代码中页面的跳转的代码

HTML meta refresh 刷新与跳转(重定向)页面
refresh 属性值 -- 刷新与跳转(重定向)页面
* refresh用于刷新与跳转(重定向)页面
* refresh出现在http-equiv属性中,使用content属性表示刷新或跳转的开始时间与跳转的网址

meta refresh示例

5秒之后刷新本页面:

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy8326')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy8326>

<meta http-equiv="refresh" content="5" />

5秒之后转到梦之都首页:

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy4565')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy4565>

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

点击提交之后再跳转

点击按钮<input type="submit" name = "submit" value="确定" />

使用POST方式<form action="X.php" method="post">

X.php页面只做判断逻辑  处理完以后

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy1611')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy1611>

<?php
//isset函数
if(isset($_POST["name"]))
{
 header("Location: XX.php?name=".$_POST["name"]);
 }
?>

注意 由于当前页面已经有输出内容所以这样跳转会在PHP中报错。

以上这些页面跳转代码都可以实现在你页面与页面之间跳转功能,有些还可实现在其它环境中实现页面跳转。

您可能感兴趣的文章:
php页面跳转函数 页面重定向
php如何实现页面跳转
js 控制页面跳转的五种方法
php页面跳转与定时跳转页面方法
js 3秒后跳转页面实例代码
php url重定向(页面跳转)的代码
php页面跳转另一页面各种跳转页面代码
PHP 登录完成跳转上一访问页面
PHP页面跳转(URL地址跳转)实现代码
PHP页面跳转的三种方法

[关闭]
~ ~