0

I have been trying to resolve this problem with all online solutions several days, and nothing was helpful. Obviously I am missing a key point as on localhost it works, but when I put it online it does not.

ERROR: Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/public_html/domain/index.php:1) in /home/public_html/domain/index.php on line 3

index.php

<?php
session_start();
include('functions/connect.php');
$page = htmlentities($_GET['page']);
include('functions/' . $page . '.func.php');

$pages = scandir('pages');

if (!empty($page) && in_array($_GET['page'] . '.php', $pages)) {
    $content = 'pages/' . $_GET['page'] . '.php';
} else {
    header('Location:index.php?page=register');
}
if (isset($_SESSION['uesername']) 
) {
    header("Location:index.php?page=member");
}
?>
<!DOCTYPE html>
<html>
    <head>
        <link href="css/mojcss.css" rel="stylesheet" type="text/css"/>

    </head>
    <body>
        <div id='content'>
<?php
include($content);
?>
        </div>
    </body>
</html>

connect.php

<?php
$link = @mysql_connect('localhost','myusername','mypass');  //or die('error');
if(!$link)
{
    $message="<strong><font color='red'>Error, try later.</font></strong><br /><br />";
    die($message.mysql_error());
}

$db = mysql_select_db('mydb'); //or die('unable to connect');
if(!$db)
{
    $message="<strong><font color='red'>Error, try later.</font></strong><br /><br />";
    die($message.mysql_error());
}
?>
mpavlovic89
  • 749
  • 3
  • 16
  • 37
  • 2
    possible duplicate of [How to fix "Headers already sent" error in PHP](http://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php) – Naruto Apr 01 '15 at 09:29
  • Unfortunately, this was not helpful :/ – mpavlovic89 Apr 01 '15 at 09:38
  • Delete `?>` from your included php files. There may be some ending new lines that will be sent as response body content to the browser – isalgueiro Apr 01 '15 at 10:09

3 Answers3

0

Check whether there is another session that has already been started on the server that is preventing your session_start() to initialize.

James Njuguna
  • 604
  • 2
  • 12
  • 24
0

Put session_start(); at the very top of functions/connect.php and make sure there is single session_start() in your code. Also restart your localhost and remove all session files from tmp directory.

Umair Hamid
  • 3,509
  • 3
  • 23
  • 25
0

1.Write ob_start() before session_start() statement.

or If solution one does not work for you than please make sure that nothing gets sent to the browser before session_start() statement. This happens in case there is a white space or some charactors before session_start() or even before tag. If this is the case, please remove spaces or charactors.It will sovle the "Cannot send session cache limiter" problem. or If both solutions does not make any difference and still you have the same problem than try to set the encoding from UTF-8. UTF-8 encoding add some characters before

MaThar Beevi
  • 294
  • 1
  • 2
  • 10