在会话中加载值后无法重定向?

时间:2013-04-26 07:29:40

标签: php

从数据库加载会话值后,下面的标题重定向给出错误?

while($row=mysql_fetch_row($res))
{
            $_SESSION['id']=$row[0];
            $_SESSION['name']=$row[1];
            $_SESSION['rollno']=$row[2];
            $_SESSION['pass']=$row[3];
            $_SESSION['email']=$row[4];
            $_SESSION['secans']=$row[5];
            $_SESSION['mob']=$row[6];     
            header("location:index.php");
 }

check.php页面上的错误

headers already sent by (output started at /home/name/public_html/fest/header.php:19) in /home/name/public_html/fest/check.php on line 40 (line 40:  header("location:index.php"); )

1 个答案:

答案 0 :(得分:1)

header()位于while loop内。将header()放在while循环之外。

它应该是这样的:

while($row=mysql_fetch_row($res))
{
            $_SESSION['id']=$row[0];
            $_SESSION['name']=$row[1];
            $_SESSION['rollno']=$row[2];
            $_SESSION['pass']=$row[3];
            $_SESSION['email']=$row[4];
            $_SESSION['secans']=$row[5];
            $_SESSION['mob']=$row[6];     

 }

          header("location:index.php");