PHP如何重定向?浅谈跳转页面的3种方法
134
用户登录功能时往往需要重定向页面,那么在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> <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>
<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>;
?>本文网址:https://my.codejie.cn/server-287.html
转载请声明来自:资源网 - PHP如何重定向?浅谈跳转页面的3种方法

![【白色新版币圈】完美运行美元币圈+安装教程+[已接支付]源码 【白色新版币圈】完美运行美元币圈+安装教程+[已接支付]源码](/uploads/image/2022032201/20220322fc2dhea2w5a.jpg)





您还没有登录,请 登录 后发表评论!
提示:请勿发布广告垃圾评论,否则封号处理!!