session_start() is different in .php and .cgi files
| From: | B�rge Strand | Date: | Sun, 11 Jan 2004 17:29:57 +0000 |
| Subject: | session_start() is different in .php and .cgi files | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-6974@lists.php.net to get a copy of this message | ||
I have written a very short sessions test program and saved it in both
.cgi and .php formats. I want to run my site as .cgi so that other
users on the same servar can't read my files.
Running as a .php file, everything seems OK. I've set the browser to
prompt for cookies. And it does just that with test4.php.
As a .cgi file, I never get prompted for the cookie. In subsequent
accesses, the isset($_SESSION['count']) is never true.
Is there an error in the way session_start() is performing header
generation? My ISP uses PHP 4.3.4.
I've tried putting 'Content-type...' in header() and also to place it
before I call session_start(). That doesn't make my program work.
The only differences between the .php and .cgi versions is that
test4.cgi contains #! /usr/local/bin/php and print 'Content-type...'.
The files are included below.
Hope you can help me out on this one!
Regards,
Børge Strand
test4.cgi:
------------
#! /usr/local/bin/php
<?php
session_start();
print 'Content-type: text/html' . "\n\n"; // Required in .cgi
file
print '<html><body>' . "\n";
print 'This is the test4.cgi file<br>' . "\n";
if (!isset($_SESSION['count']))
$_SESSION['count'] = 1;
else
$_SESSION['count']++;
print 'Your visit number ' . $_SESSION['count'] . "\n";
print '</body></html>' . "\n";
?>
------------
test4.php:
------------
<?php
session_start();
print '<html><body>' . "\n";
print 'This is the test4.php file<br>' . "\n";
if (!isset($_SESSION['count']))
$_SESSION['count'] = 1;
else
$_SESSION['count']++;
print 'Your visit number ' . $_SESSION['count'] . "\n";
print '</body></html>' . "\n";
?>
------------