Welcome to WebmasterWorld Guest from 54.158.54.179

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Need help, New to PHP

Getting a Session Error...

     
4:39 pm on Nov 6, 2006 (gmt 0)

WebmasterWorld Senior Member crobb305 is a WebmasterWorld Top Contributor of All Time 10+ Year Member



I have created a form using PHP. I am trying to include this form on regular html pages, but I am getting a session error. Here is what I have set up:

example.htm calls external .php file using
include("../file.php");

Inside file.php, session is started using
session_start();

Now, when I view example.htm, the form loads within the document just fine, but there is a warning:

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /example.htm:6) in /file.php on line 14

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /example.htm:6)

Apparently, a session can't be started in the php file since one was already started when information was first sent to the browser from example.htm. So, my question is, how do I get around this? How can I pass the session info from the parent document to the php without starting a new one?

This is so irritating.

4:45 pm on Nov 6, 2006 (gmt 0)

5+ Year Member



The 2 main ways you get around it are:

1) Make the first part of your page php and use output buffering

2) Make the first part of your page php and the first command a session_start();

When I say make the first part php, that means no html, or even spaces must come before the first <?php tag.

Additional hint ... look up SID in the php manual, if you wish to explicitly pass the session identifier.

Hope this helps.

7:16 pm on Nov 6, 2006 (gmt 0)

WebmasterWorld Senior Member crobb305 is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Is it better to just load the content using IFRAME?
8:06 pm on Nov 6, 2006 (gmt 0)

5+ Year Member



It really depends on what you seek to achieve but PHP will let you do many things that iframes will not. If your "included" file needs sessions, then you will still have to obey the rules I outlined above.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month