--- Børge Strand <[EMAIL PROTECTED]> wrote:
> I have a problem with html headers using sessions.

I think you mean HTTP headers.

> I guess it has to do with the Content-type line.

Yes, and you seem to have a fundamental misunderstanding between using PHP
as an Apache module versus using PHP as a CGI interpreter.

I will try to explain using your code:

> Here's test3.cgi:
> ======================================================
> #! /usr/local/bin/php
> <?php
>     print 'Content-type: text/html' . "\n\n";

When you are running as a CGI, you can set the Content-Type header in this
way. However, as soon as you send two sequential newlines, you are
indicating the end of the headers and the beginning of the content.

>     session_start();

So, when you have this on the next line, PHP cannot set the Set-Cookie
header that it is likely trying to set (in addition to whatever
cache-related headers it may be setting, depending on your configuration).
This is because you have already indicated the end of the headers in your
previous line. This is the danger in writing your own headers in this way;
you become responsible for adhering to the proper format of things.

> And test3.php:
> ======================================================
> <?php
>     session_start();
> //  print 'Content-type: text/html' . "\n\n"; // only in .cgi version!

While it's not necessary to specify Conetnt-Type here, you can do so using
the header() function:

header('Content-Type: text/html');

Anything that you print or echo is going to be considered as part of the
content, not part of the headers.

Hope that helps.

Chris

=====
Chris Shiflett - http://shiflett.org/

PHP Security Handbook
     Coming mid-2004
HTTP Developer's Handbook
     http://httphandbook.org/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to