-1

I've read a lot on other forums, they said that the error was that there was White-space before the session_start but I'm extremely sure there isn't, my file is encoded in UTF8 without BOM so that white-space problem should be fine and it's working perfectly on local (I'm using easyphp). Still, as soon as I put it online, it pops me those problem.anyone can help? They're telling those two lines of error online :

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent

This is my code:

<?php
session_start();
?>
GolezTrol
  • 114,394
  • 18
  • 182
  • 210
  • 1
    I can't believe `` gives you that error, please post your full code. – Daan Jul 29 '15 at 07:54
  • Is that all the output you got? No file name and line number? No other output? Also, is that all the code you got, or is this included from another file? – GolezTrol Jul 29 '15 at 07:58
  • Add `` top of the page – Arun Kumar Jul 29 '15 at 07:59
  • connect_error) { die("Connection failed: " . $conn->connect_error); } $uname=$_SESSION['name']; $sql = "SELECT * FROM consultant WHERE username='uname' "; $result = $conn->query($sql); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { } else { echo "0 results"; } $conn->close(); ?> – Subashini Dharmalingam Jul 29 '15 at 08:04
  • This is my code if i am using session_start(); its shown above warning message.how to resolve this? – Subashini Dharmalingam Jul 29 '15 at 08:06
  • The username get from previous page using session – Subashini Dharmalingam Jul 29 '15 at 08:06
  • my webpage shows Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/content/44/8512544/html/sarah_philip.php:10) in /home/content/44/8512544/html/sarah_philip.php on line 149 like this – Subashini Dharmalingam Jul 29 '15 at 08:08
  • http://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php – Amit Rana Jul 29 '15 at 08:16

2 Answers2

0

The warning means that the HTTP headers were already sent and they cannot be modified anymore. You have to make sure you do not send any content before session_start. Put it on top of your very first PHP script, before any echo or HTML and you will be fine.

oshell
  • 8,923
  • 1
  • 29
  • 47
0

There is certainly an error in your code - you have an else condition attached to a while loop and perhaps you posted it in error but why are there two session_start() calls? Assuming that this is one page!

<?php 
    session_start(); 
    $uname=$_SESSION['name'];
?>
<?php 
    /*session_start();*/
    $servername = "68.178.143.40"; 
    $username = "applicant123"; 
    $password = "Applicant@123"; 
    $dbname = "applicant123"; 

    $conn = new mysqli($servername, $username, $password, $dbname); 
    if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } 
    $uname=$_SESSION['name']; 
    $sql = "SELECT * FROM consultant WHERE username='uname' "; 
    $result = $conn->query( $sql ); 
    if ( $result->num_rows > 0 ) {

    /* Here is a problem - there should be no "else" */
    /*
    while( $row = $result->fetch_assoc() ) {

    } else { 
        echo "0 results"; 
    }
    */


    while( $row = $result->fetch_assoc() ) {
        /* do stuff with recordset */
    }

    $conn->close();
?>
Professor Abronsius
  • 33,063
  • 5
  • 32
  • 46