php中重定向网页跳转 php中重定向网页跳转方法总结案例教程

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

php中重定向网页跳转 php中重定向网页跳转方法总结案例教程

yAngrUiLin啊   2021-08-06 我要评论
想了解php中重定向网页跳转方法总结案例教程的相关内容吗,yAngrUiLin啊在本文为您仔细讲解php中重定向网页跳转的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:php重定向,php重定向页面跳转,下面大家一起来学习吧。

PHP中重定向网页跳转页面的方法(共三种)

第一种:利用header()函数进行重定向,这也是我用的较多的。(注意!locationhe和“:”之间不能有空格,否则无作用!)

<?php
    header('content-type:text/html;charset=uft-8);
    //重定向页面
    header('location:index.php');
 ?>

第二种:利用HTML 头部中的 meta标签,定义http-equiv=refresh 和content=”跳转花费的时间(秒为单位);url=跳转地址”

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    //跳转页面,跳转时间:3秒钟,目标地址:index.php
    <meta http-equiv="refresh" content="3;url=index.php">
    <title>skip...</title>
</head>

或者

<?php
header('content-type:text/html;charset=utf-8');
$url='index.php';
 ?>
 <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    //跳转页面,跳转时间:2秒钟,目标地址:index.php
    <meta http-equiv="refresh" content="2;url=<?php echo $url; ?>">
    <title>skip...</title>
</head>

第三种:利用javascript进行跳转

<?php
header('content-type:text/html;charset=utf-8');
$url='index.php';
//立即跳转至目标页面
echo <script>window.location.href='$url';</script>;
?>

以上就是PHP中重定向页面的三种方法。

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们