2011-03-14 111 views
0
if ($count == 1) { 
    $_SESSION["authenticated"] = $row[0]; //register session with user id 
    header("Location: success.php"); 
} 

success.php:会话注册的问题?

<? 
session_start(); 
if (isset($_SESSION['authenticated'])) { 
    header("Location: view.php"); 
} else { 
    header("Location: index.php"); 
} 
?> 

它似乎并不奏效它一直我重定向到index.php,如会话从来没有登记。我究竟做错了什么?

+1

添加在session_start();到第一个文件。 – eisberg 2011-03-14 11:59:40

+0

哇@eisberg修复它。非常感谢!在这里发帖让我可以给你一个绿色的复选标记? :) – Kyle 2011-03-14 12:01:33

+0

你确定你没有得到E_NOTICE错误的地方?检查你的日志。您没有提供足够的代码来进行调试。这段代码中没有任何特定的内容会导致错误。 – arnorhs 2011-03-14 12:03:03

回答

2

您需要添加在session_start()进入第一块

if ($count == 1) { 
    session_start(); 
    $_SESSION["authenticated"] = $row[0]; //register session with user id 
    header("Location: view.php"); 
    exit; 
} 

并且在其success.php没有意义的。只需直接将用户view.php
,你必须再次验证用户身份验证:

<? 
session_start(); 
if (empty($_SESSION['authenticated'])) { 
    header("Location: index.php"); 
    exit; 
} 
?> 

exit是位置后必须做的,或者你的保护将没有保护

+0

再次感谢Col! – Kyle 2011-03-14 12:02:30

+0

这是一个好主意。我真的不需要'success.php.'谢谢。我也会确保也加入退出;在所有标题重定向下。 – Kyle 2011-03-14 12:33:11