Wednesday, May 6, 2009

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

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/direct/public_html/admin/index.php:1) in /home/direct /public_html/admin/header.php on line 1

how to solve above php error  and what is session handling in php.

A session refers to all the connections that a single client might make to a server in the course of viewing any pages associated with a given application. Sessions are specific to both the individual user and the application. As a result, every user of an application has a separate session and has access to a separate set of session variables.

This logical view of a session begins with the first connection to an application by a client and ends after that client's last connection. However, because of the stateless nature of the web, it is not always possible to define a precise point at which a session ends. A session should end when the user finishes using an application. In most cases, however, a web application has no way of knowing if a user has finished or is just lingering over a page.

Therefore, sessions always terminate after a time-out period of inactivity. If the user does not access a page of the application within this time-out period, ColdFusion interprets this as the end of the session and clears any variables associated with that session.

bool session_start ( void )

session_start() creates a session or resumes the current one based on the current session id that's being passed via a request, such as GET, POST, or a cookie.

If you want to use a named session, you must call session_name() before calling session_start().

session_start() will register internal output handler for URL rewriting when trans-sid is enabled. If a user uses ob_gzhandler or like with ob_start(), the order of output handler is important for proper output. For example, user must register ob_gzhandler before session start.

If you are using cookie-based sessions, you must call session_start() before anything is outputted to the browser.

Only when I had uploaded my pages from my home development server to my hosted website.  the same page worked fine in development, so there must be a difference in the php setup, but since this is a site that hosts many different clients web sites, I can't get them to change thier config.

After a little bit of research and trial and error, I found the cure was to move the line:
 





No comments: