警告:session_start() [function.session-start]:无法发送会话 cookie - 头已经发送(输出开始于 [英] Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at

查看:62
本文介绍了警告:session_start() [function.session-start]:无法发送会话 cookie - 头已经发送(输出开始于的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 session_start(); 中有错误.我是指我们的网站,但我不会修复该错误.我的第二个问题是什么是 php 中的空格,如何清除它?

hai i have error in session_start();. i was refer our site but i will not fix that error. my second question is what is whitespace in php, how to clear that ?.

注意:此代码在本地主机上工作这是我的代码

Note: This code working in localhost this is my code

<?php
  session_start();
  $message = "";
  if (count($_POST) > 0) {
      $conn = mysql_connect("198.33.225.54:3306", "test", "test");
      mysql_select_db("test", $conn);
      $result = mysql_query("SELECT * FROM candidate WHERE user_name='" . $_POST["userName"] . "' and pass_word = '" . $_POST["password"] . "'");
      $row    = mysql_fetch_array($result);
      if (is_array($row)) {
          $_SESSION["user_id"]   = $row['id'];
          $_SESSION["user_name"] = $row['user_name'];
      } else {
          $message = "<font color='#FF0000'>Invalid Username or Password!</font>";
      }
  }
  if (isset($_SESSION["user_id"])) {
      header("Location:profile.php");
  }
?> 

推荐答案

1) 写 ob_start();在代码的顶部,即 <?php 之后和 session_start();

1) Write ob_start(); at the top of your code,i.e., after <?php and before session_start();

另外,写 ob_flush();在代码的末尾,即在 ?>

Also, write ob_flush(); at the end of the code,i.e., before ?>

这将帮助您处理警告,警告:session_start()....

This will help you for the warning, Warning: session_start()....

2) 空白是代码中任何不需要的空间,尤其是在 php 标签 <?php?>

2) Whitespace is any unwanted space in the code, especially before and after php tags <?php and ?>

这篇关于警告:session_start() [function.session-start]:无法发送会话 cookie - 头已经发送(输出开始于的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆