-1

I know this is a fairly common question on here but I am creating a website for my Uni module and my init and config files are causing an error on EVERY page and I can't figure out why. I include my init file on every page and my init file includes my config file! There is nothing being output on line 2 of the init file or in any of the files. I haven't left changed my config variables for this post but this is not what is causing the error.The error is

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /customers/a/b/7/mywebsite/httpd.www/currentpage.php:1) in /customers/a/b/7/mywebsite/httpd.www/config/init.php on line 2

init.php

<?php
session_start();
require_once 'config.php';
?>

config.php

 <?php

    //Database depends on host
    $db['hostname'] = 'myhostname';
    $db['username'] = 'username';
    $db['password'] = 'mypassword';
    $db['database'] = 'database';
    $db['dbdriver'] = 'mysqli';

    //$connection = new mysqli($hostname, $username, $password, $databaseName);

    $connection = new mysqli($db['hostname'], 
    $db['username'],$db['password'],$db['database'] );


    ?>

Currentpage.php

<!DOCTYPE html>
  <head>
      <html lang="en">
  </head>
  <?php
  require 'header.php';

  ?>



    <!-- Primary Page Layout
    –––––––––––––––––––––––––––––––––––––––––––––––––– -->


        <?php
        require 'leftnav.php';
        ?>

 <?php require 'footer.php'; ?>


         </div>
    </div>

  <!-- End Document
    –––––––––––––––––––––––––––––––––––––––––––––––––– -->

2 Answers2

0

I believe you are including init.php in header.php. Remove it and include it in currentpage.php before:

<?php include('init.php'); ?>
<!DOCTYPE html>

Or better yet add the following in header.php, and include init.php before any html tag, Like:

<?php include('init.php'); ?>
<!DOCTYPE html>
  <head>
      <html lang="en">
  </head>

There should be no output that should be sent before session_start().

mega6382
  • 9,211
  • 17
  • 48
  • 69
0

Because you have already sent your header by using <!DOCTYPE html> prior session_start();.

Artis Zel
  • 61
  • 4