homepage Welcome to WebmasterWorld Guest from 54.204.231.110
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Need help, New to PHP
Getting a Session Error...
crobb305




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

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.

 

dragonthoughts




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

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.

crobb305




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

Is it better to just load the content using IFRAME?

dragonthoughts




msg:3147812
 8:06 pm on Nov 6, 2006 (gmt 0)

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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved