dongzhang7961 2014-03-04 10:09 采纳率: 0%
浏览 26
已采纳

PHP重定向是否适用于页面顶部?

I am following along with a Lynda.com tutorial on php and am learning about php redirects. Using header("Location: basic.html"), the tutor says for a redirect to work it must be the very first thing on a page. However, I tested that by putting the php code within the tags and the redirect still worked. I have looked at other online resources and they too say that there should be nothing above the redirect. Are the resources I have looked at simply out of date or am I missing a point here?

Thanks

I am running XAMPP on my local machine. My code is: Redirect

<?php
// This is how you redirect to a new page
    function redirect_to($new_location) {
        header("Location: " . $new_location);
            exit;       
    }

    $logged_in = $_GET['logged_in'];

    if($logged_in == 1) {
    redirect_to("basic.html");
    } else {
        redirect_to("http://www.google.co.uk");
    }
    ?>

</body>

  • 写回答

7条回答 默认 最新

查看更多回答(6条)

报告相同问题?

悬赏问题

  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了
  • ¥100 H5网页如何调用微信扫一扫功能?
  • ¥15 讲解电路图,付费求解
  • ¥15 有偿请教计算电磁学的问题涉及到空间中时域UTD和FDTD算法结合的
  • ¥15 three.js添加后处理以后模型锯齿化严重