-1

i have error like Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at G:\PleskVhosts\globaledudeals.com\translatemasters\list.php:1) in G:\PleskVhosts\globaledudeals.com\translatemasters\list.php on line 87

<?php
ob_start();
session_start(); //**---> This is 87th line**
$message="";
if(count($_POST)>0) {
$conn = mysql_connect("198.72.225.45:3360","test","xxxx");
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");
}
ob_flush();
?>  
Nisha Chinnapa
  • 97
  • 1
  • 2
  • 8
  • You've already asked this question, and answers have been given: http://stackoverflow.com/questions/29429433/warning-session-start-function-session-start-cannot-send-session-cookie – Daan Apr 03 '15 at 10:53
  • Why you ask again and again same question? – Alive to die - Anant Apr 03 '15 at 10:55
  • it showing error, i can't find the error ... – Nisha Chinnapa Apr 03 '15 at 10:56
  • If output has been sent, then so have the headers, you can't call functions that require certain headers (cookies, sessions, `header` calls...), hence: use output buffering (`ob_start`) and make sure there is nothing (not even a piece of whitespace) before your php opening tag (` – Elias Van Ootegem Apr 03 '15 at 11:06

1 Answers1

0

See if there are any spaces before very first <?php at the start of the page; if so, remove that space and see the result...
Also, always start the session at the top of the page before anything else (session_start()).

MarcoS
  • 17,323
  • 24
  • 96
  • 174