跳转

来源:互联网 发布:挪威和丹麦知乎 编辑:程序博客网 时间:2024/05/29 14:03

跳转分为:立即跳转,提示跳转

立即跳转:

eg:jump_1.php

<?php

  header('location:jump_2.php');

//file_put_contents('./after_header.text','after header function');

die();

?>

    jump_2.php

<?php

echo "hello.jump_2";

?>

输出结果:hello.jump_2

注:1·header('location:')前不能跟输出内容、其后要加die函数【若在header()钱有输出内容可能不报错:在服务器内部有一个配置文件叫:output_buffering=4096此时为不报错状态,但是output_buffering=off是就会报错

   2·header('location:')后的函数会正常执行,虽然看不到,但是我们可以通过一个文件函数来证明【看有没有after_header.txt文件即可】

因此跳转后要立即终止当前脚本的执行,才符合跳转逻辑!

提示跳转:header('refresh:time;url=目标url');

eg:jump_1.php

<?php

header('refresh:3;url=jump_2.php');

?>

jump_2.php

<?php

header('content-type:text/html;charset=utf-8');

echo "hello.jump_2";

//echo "管理员有误";

die();

?>

输出结果:停留3秒后输出hello.jump_2

注:在停留的3秒中可以输出想要提示的内容,通过显示输出完成提示后跳转;

header()后的代码会执行,因此在处理好跳转操作后,脚本应该被die掉!!




0 0