【问题标题】:Warning : session_start()警告:session_start()
【发布时间】:2012-10-19 19:07:45
【问题描述】:

我在使用 login.php 文件时收到警告。帮我删除这个警告......----

警告:session_start() [function.session-start]:无法发送会话缓存限制器 - 标头已发送(输出开始于 /home/fundumob/public_html/app_create/index.php:35)在 /home/fundumob/ public_html/app_create/login.php 在第 1 行

 <?php session_start();?>
 <?php 
 include("lib/config.php");

 if(isset($_POST["tb_login"]))
 {
 $myusername=$_POST['log_email'];
 $myuser_password=$_POST['log_password']; 

 if(!empty($myusername) && !empty($myuser_password))  
  {
 $sql="SELECT * FROM act_member WHERE   password='$myuser_password' and               
  email='$myusername'";
$result=mysql_query($sql);
 // Mysql_num_row is counting table row
 $count=mysql_num_rows($result);
 // If result matched $myusername and $mypassword, table row must be 1 row
 if($count==1){
 $rows=mysql_fetch_row($result);
 $_SESSION['user_id']= $rows[0];
 $_SESSION['mem_id']=$rows[1];
 $_SESSION['fname']=$rows[2];
 $_SESSION['lname']=$rows[3];
 header("location:profile.php");    }
 else { 

echo "sorry you entered wrong password or email id";
}

 }
 }

 ?>

【问题讨论】:

标签: php warnings


【解决方案1】:

试试这个:

您忘记在标头声明后添加 exit()...

<?php 

session_start();
include("lib/config.php");

if(isset($_POST["tb_login"])){

    $myusername=$_POST['log_email'];
    $myuser_password=$_POST['log_password']; 

    if(!empty($myusername) && !empty($myuser_password)){
        $sql="SELECT * FROM act_member WHERE   password='".$myuser_password."' and               
        email='".$myusername."'";
        $result=mysql_query($sql);
        // Mysql_num_row is counting table row
        $count=mysql_num_rows($result);
        // If result matched $myusername and $mypassword, table row must be 1 row

        if($count==1){

            $rows=mysql_fetch_row($result);
            $_SESSION['user_id']= $rows[0];
            $_SESSION['mem_id']=$rows[1];
            $_SESSION['fname']=$rows[2];
            $_SESSION['lname']=$rows[3];
            header("Location: profile.php");    
            exit(); // <-------------------- add this else the page will not redirect and you will get a header error
        }
        else { 
            echo "sorry you entered wrong password or email id";
        }

    }
}

?>

【讨论】:

  • 我添加了退出功能,但它仍然无法正常工作。出现同样的警告
  • '
【解决方案2】:

您不能在此处使用 session_start(),如警告中所述,/home/fundumob/public_html/app_create/index.php:35 中已经输出了一些内容

检查一下

【讨论】:

    【解决方案3】:

    如果您在&lt;?php session_start();?&gt; 之上包含任何其他文件,请确保&lt;?php session_start();?&gt; 存在于第一行的最顶部文件中。可能是您的 config.php 或您包含的其他文件。

    【讨论】:

      猜你喜欢
      • 2013-06-11
      • 1970-01-01
      • 1970-01-01
      • 2013-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-28
      相关资源
      最近更新 更多