Jump to content

Recommended Posts

Hello I am starting to use php.I am trying to work with sessions,and have come up with error from a small php file.

<?php
        session_start();
        
         $user = $_SESSION['user'];
        echo $_SESSION['user'];
?>

 

There are 2 warnings of on Warning: session_start().

 

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\xampp\htdocs\Sessions\index.php:8) in C:\xampp\htdocs\Sessions\index.php on line 10

 

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\Sessions\index.php:8) in C:\xampp\htdocs\Sessions\index.php on line 10

 

How do I enable my php install to use sessions like I have demonstrated?

 

 

Link to comment
https://forums.phpfreaks.com/topic/155769-beginning-sessions-with-problem/
Share on other sites

Read the error. You already have output on line 8 of index.php.

 

You cannot do any type of header function after output has been sent, this includes white spaces, echo's print's etc.

 

Show us the first 15 lines of index.php and we can help you resolve the issue. As the code you have shown here does not correspond with the error you have pasted.

 

EDIT:

As a side note, HEADER ERRORS - READ HERE BEFORE POSTING THEM  Sticky at the top of this forum.

Thanks for the quick reply.

I modifed the code to just php start my session like so:

<?php
        session_start();
?>

Same as actual layout source code.

 

Then got same error.

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\xampp\htdocs\Sessions\index.php:8) in C:\xampp\htdocs\Sessions\index.php on line 10

 

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\Sessions\index.php:8) in C:\xampp\htdocs\Sessions\index.php on line 10

 

Wow I got same error? how come this gee what is going wrong um?

 


<?php
session_start();

 

That is considered a whitespace hence output to the browser.

 

<?php
echo 'test';
session_start();

 

That is consider output as well, and will cause the error.

 

<?php
session_start();
echo 'test';

 

That is a valid session_start() given that there is nothing included above etc. You must[/m] have output being started somewhere or else you would not get that error, particularly on line 8 in sessions/index.php as that is what the error states:

 

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\xampp\htdocs\Sessions\index.php: 8 ) in C:\xampp\htdocs\Sessions\index.php on line 10

 

Your session_start code is apparently on line 10, given that error message.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.