PHP中重定向网页跳转页面的方法:1、利用【header()】函数进行重定向;2、利用HTML头部中的meta标签;3、利用javascript进行跳转。
【相关学习推荐:php图文教程】
PHP中G ? | c % W W ^ =重定向网页, ) F跳转页面的方法:
hhw:用第一种方法可以将:http://12u Z X B r7.0.0.1/tp5 简化为http://127.0.0.1,即将www目录下的index.php文件写入第一种中的php代码:
<O , Q * / _?php header('con t $ x j a u Dtent-type:text/html;charset=uf_ x s t E q Y S ut-8'); header('lk A p Q *ocation:tp5/index.php'); ?>
或直接:
<?php header('6 + S u 7 3content-type:text/html;chb [ warset=uft-8- ; 0'); hL ~ K m 6 _ N B Feader('location:tp5/public/index.php'); ?>
第一种:利用header()Y N ! _ ] A B j `函数进行重定向,这也是我用的较多的。(注意!locag O S ` ttionhe和“:”之间不能有空格,否则无作用!)
<?php header('content-typ) c M me:text/html;charset=uft-8); /a r n e 9 1 Z I D/重定向页面 headere ) { 7('location:index.j h / % v ~ pphp'); ?>
第二种:利用HTML 头部中的 meta标签,定义http-Q u 7equiv=refresh 和content=”跳转花费的时间(秒为单位);url=跳转地址”
<!DOCTU Z $ 2 V B ; MYPE html>A L D . } R I; <html> <head> <meta charsP + : h f S m j iet="UTF-8"> //跳转页面,跳转时间:3秒钟,目标地址:index.php <meta http-equi5 K X 4 ^ qv="refresh" content="3;url=index.php"> <title>skip...</title> &d : ~ Y M 1 R } |lt;/head>
或者
<?php header('content-type:text/html;charset=utf-8'); $url='index.php'; ?&gj j ^ 5 f P It; <!o % ? EDOCTYPE html> <html> <head> <meta charset="UTF-8"> //跳转页面,跳转时间:2秒钟,目标地址:index.php <meta http-equiv="refresh" content="2;url=<?php echo $b : 3 d Q 1 ~url; ?>">u D J 1 k <title>skip...</1 ( v l , C k b 6title> </head>
第三种:利用javascript进行跳转
<?php header('content-type:text/html;charseM S - 4t=utf-8'); $url='index? _ = D a r ^.php'; //立即跳转至目标X ) V X t a *页面 echo <scripY U ?t>window.location.href='https://www.php.cn/$url';</script>; ?>
相关学习推荐:php编程(视频)
以上就是PHP中如何重e Z T h z ] X定向网页跳转页面的详细内容。