• You are not logged in. | Login

Post a reply

November 14, 2006 8:34 pm

IBdaMac
Member
Ranks

php session problem

Hi, I have a problem using 'sessions' in PHP, can someone help me?

I have a website where I want to allow users to login to post images and files, but when I try my login script I'm getting this error:

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

and the session doesn't work.  Please help!


 

 

November 14, 2006 8:45 pm

phppat
Member
Ranks

Re: php session problem

This is a pretty common problem for people starting out with PHP sessions. 

This is almost always caused by some other output before the 'session_start()' function in your script, either html, a php print or echo statement, or even whitespace in some cases.

You should be sure that there is *nothing* outputted before the session_start() function.  The easiest fix is usually starting the session first, before any other PHP or HTML, for example:

<?php
session_start();

....
other PHP code
---
?>
<html>
 <body>
...
other HTML code
...
 </body>
</html>

Again, be certain there is no whitespace before the opening tag, as some webservers may try to output the spaces it to the browser before running the PHP code.

Hope that helps!

-- PHPPat

Last edited by phppat (November 14, 2006 8:47 pm)


PHP monster

 

 

November 14, 2006 9:09 pm

IBdaMac
Member
Ranks

Re: php session problem

Thanks, that was it!

I had my html tag before the php code, and now it works!

Last edited by IBdaMac (November 14, 2006 9:11 pm)


 

 
  • Actions
  • Top
ITCrimea. Ukraine Web Development Company. Professional Developers and Web Designers Team
Custom Web Designs, Internet Applications, E-Commerce Websites, Interactive Sites, Database-Driven Sites and Services