1

I included login.php and loggedin.php files in index.php.

both login.php and index.php has no session_start(); and only loggedin.php has session_start(); in it.

but still I am getting the following errors when I open index.php:

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/content/98/10855698/html/symp13/index.php:110) in /home/content/98/10855698/html/symp13/loggedin.php on line 2

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/content/98/10855698/html/symp13/index.php:110) in /home/content/98/10855698/html/symp13/loggedin.php on line 2

The loggedin.php is as follows:

<?php
session_start();
if (isset($_SESSION['username'])) {
echo 'you are logged in as'.' '.$_SESSION["username"];
echo '<form action="upload.php" method="post" enctype="multipart/form-data" name="upload">'.'<input type="file" name="file" /><input type="submit" name="submit" />'.'</form>'; }
else {
echo 'You need to login in with your account for submitting abstract or for applying for tutorials!';
echo 'Click here to'.' '.'<a href="login.php">login</a>';
}
?>

login.php includes a form with action set to login_check.php which includes session_start();. But I dont think that is the problem..because, it cant be run until the form is submitted.

And if I run only loggedin.php in a separate file. it is showing no errors.

I am confused. Please tell me how to solve this and also the cause.

enter image description here

GP92
  • 433
  • 1
  • 12
  • 30

2 Answers2

2

As the documentation says:

To use cookie-based sessions, session_start() must be called before outputing anything to the browser.

This means that there must be no whitespace before the call to session_start(), even whitespace. So, your index.php file must look something like this:

<?php

  include 'loggedin.php'; //containing session start
  include 'login.php';

  echo 'other output';
?>
more output here
LeonardChallis
  • 7,759
  • 6
  • 45
  • 76
1

Put your:

<?php ... ?>

on top of everything (above body). It won't break anything. Then just position using CSS as required.

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141