Hi there,

I have a problem setting my headers right with php running as .cgi. I
have to specify a Content-type for the cgi file to work. But how
should I do both that and start a session?

I have a few options:

#! /usr/local/bin/php
<?php
    session_start();
    print 'Content-type: text/html' . "\n\n";

This way $_SESSION['count'] stays unset even though I say
$_SESSION['count'] = 1; in my program.

To swap the two lines won't work because I heard \n\n terminates the
header portion. Anyway, here goes:

#! /usr/local/bin/php
<?php
    print 'Content-type: text/html' . "\n\n";
    session_start();

Now I get "Warning: session_start(): Cannot send session cookie -
headers already sent by... line 3" and then "Warning: session_start():
Cannot send session cache limiter - headers already sent...".

I have tried replacing print 'Content-type: text/html' . "\n\n"; by
print 'Content-type: text/html' . "\n"; (one \n instead of two) with
exactly the same result. With no \n at all I only get "Warning:
session_start(): Cannot send session cache limiter - headers already
sent".

The next thing I try is to replace print 'Content-type: text/html' and
the \n's by sending the same text in header(). This variety gives me a
"500 Internal Server Error" independant on the number of \n's.

Anyway, here's all my code. No matter what I do it always prints "Your
visit number 1". $_SESSION['count'] doesn't get increased at all!

========================
#! /usr/local/bin/php
<?php
    print 'Content-type: text/html' . "\n\n";
    session_start();
    print '<html>' . "\n";
    print '<body>' . "\n";

    if (!isset($_SESSION['count']))
    {
        $_SESSION['count'] = 1;
    }
    else
    {
        $_SESSION['count']++;
    }

    print 'Your visit number ' . $_SESSION['count'] . "\n";
    print '</body>' . "\n";
    print '</html>' . "\n";
?>
========================

I hope you can help me out getting my headers straight.


Regards, 

Børge

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

Reply via email to