【问题标题】:Redirect in the same page doesnt work?在同一页面重定向不起作用?
【发布时间】:2014-02-25 15:06:00
【问题描述】:

我有这个代码:

// index.php
if(!isset($_SESSION['user']) && !isset($_SESSION['id']){    
     // My Code 
     if($ris1['pass'] == $pass)){ // it controls if the pass the user inserts is true...
         $_SESSION['user'] = $ris1['user'];
         $_SESSION['id'] = $ris1['id'];
         die(header("Location: index.php")); // the same page 
     }
} else { 
     // My Code 
}

我插入:die(header("Location: index.php")); 用于自动重定向页面,但如果传递正确,它会保存我的会话,但是,当我重定向用户时,用户会看到同一页面的一半,如果 $_SESSION没有定义,但 $_SESSION 是 isset,我想看看我在其他(在我的代码中)有什么我必须更新页面...... 我尝试使用 ob_start() ,但它不起作用...... 为什么我的页面不会自动重定向并转到 else 中?

【问题讨论】:

  • 你是否在index.php开头开始会话?
  • 记住,根据当前版本的HTTP/1.1标准,RFC 2616,Location头的值必须是绝对URI...不知道是不是问题的解决方案,但请考虑到这一点。

标签: php redirect


【解决方案1】:

在中止当前代码之前尝试重定向:

if(!isset($_SESSION['user']) && !isset($_SESSION['id'])) {    
     // My Code 
     if($ris1['pass'] == $pass)){ // it controls if the pass the user inserts is true...
         $_SESSION['user'] = $ris1['user'];
         $_SESSION['id'] = $ris1['id'];
         header("Location: index.php"); // the same page 
         die();
     }
} else { 
     // My Code 
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-04
    • 2013-08-16
    相关资源
    最近更新 更多