FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » session_start() should return FALSE but does not
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
session_start() should return FALSE but does not [message #170292] Wed, 27 October 2010 07:49 Go to next message
Rene[1] is currently offline  Rene[1]
Messages: 2
Registered: October 2010
Karma: 0
Junior Member
Hi,

I have played around with session_start() and found in the php manual,
that session_start() returns FALSE when php failed to start the
session (in php >= 5.3.0). So I took a php6dev (quite old from March)
and wrote the following script:

<?php
if (version_compare(phpversion(), '5.3.0') >= 0) {
if (session_start() == TRUE) {
echo "Session successfully started\n";
echo $_SESSION['check'] . "\n<br>";

$_SESSION['check'] = "Session works";
}
else
echo "Session could not be started!\<br>";
}
phpinfo();
?>

This script should return "session works" when the script is loaded
the second time. This works fine. Then I added a space in the first
line to trigger an error. This is what I got:

Warning: session_start() [function.session-start]: Cannot send session
cookie - headers already sent by (output started at ******/
test.php6:2) in /******/test.php6 on line 4

Warning: session_start() [function.session-start]: Cannot send session
cache limiter - headers already sent (output started at ******/
test.php6:2) in ******/test.php6 on line 4
Session successfully started

A reload does not lead to the message "Session works" so I assume that
the session has not been created successfully although session_start()
returns TRUE. Unfortunately, this old version of php6 is the only one
that I have available that is >=5.3.0. Is that fixed in later
versions? Does it work as expected in 5.3.0? Am I wrong somewhere?

Rene
Re: session_start() should return FALSE but does not [message #170294 is a reply to message #170292] Wed, 27 October 2010 10:10 Go to previous messageGo to next message
alvaro.NOSPAMTHANX is currently offline  alvaro.NOSPAMTHANX
Messages: 277
Registered: September 2010
Karma: 0
Senior Member
El 27/10/2010 9:49, Rene escribió/wrote:
> I have played around with session_start() and found in the php manual,
> that session_start() returns FALSE when php failed to start the
> session (in php>= 5.3.0). So I took a php6dev (quite old from March)
> and wrote the following script:
>
> <?php
> if (version_compare(phpversion(), '5.3.0')>= 0) {
> if (session_start() == TRUE) {
> echo "Session successfully started\n";
> echo $_SESSION['check'] . "\n<br>";
>
> $_SESSION['check'] = "Session works";
> }
> else
> echo "Session could not be started!\<br>";
> }
> phpinfo();
> ?>
>
> This script should return "session works" when the script is loaded
> the second time. This works fine. Then I added a space in the first
> line to trigger an error. This is what I got:
>
> Warning: session_start() [function.session-start]: Cannot send session
> cookie - headers already sent by (output started at ******/
> test.php6:2) in /******/test.php6 on line 4
>
> Warning: session_start() [function.session-start]: Cannot send session
> cache limiter - headers already sent (output started at ******/
> test.php6:2) in ******/test.php6 on line 4
> Session successfully started
>
> A reload does not lead to the message "Session works" so I assume that
> the session has not been created successfully although session_start()
> returns TRUE. Unfortunately, this old version of php6 is the only one
> that I have available that is>=5.3.0. Is that fixed in later
> versions? Does it work as expected in 5.3.0? Am I wrong somewhere?

The manual page does not state what "successfully started" means. I've
been testing it myself in PHP/5.3.3 under Windows XP and I've been
unable to make it return FALSE. It returns TRUE when it starts a new
session, it returns TRUE when it resumes a previous session, it returns
TRUE when session_start() was already called, it returns TRUE when the
session directory does not exist... If there's a situation when it will
eventually return FALSE, I haven't been able to discover it.


--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--
Re: session_start() should return FALSE but does not [message #170295 is a reply to message #170294] Wed, 27 October 2010 10:13 Go to previous messageGo to next message
webmaster is currently offline  webmaster
Messages: 5
Registered: October 2010
Karma: 0
Junior Member
""lvaro G. Vicario"" <alvaro(dot)NOSPAMTHANX(at)demogracia(dot)com(dot)invalid> wrote in
message news:ia8tql$rb7$1(at)news(dot)eternal-september(dot)org...
> El 27/10/2010 9:49, Rene escribi/wrote:
<snip>
> The manual page does not state what "successfully started" means. I've
> been testing it myself in PHP/5.3.3 under Windows XP and I've been unable
> to make it return FALSE. It returns TRUE when it starts a new session, it
> returns TRUE when it resumes a previous session, it returns TRUE when
> session_start() was already called, it returns TRUE when the session
> directory does not exist... If there's a situation when it will eventually
> return FALSE, I haven't been able to discover it.
>

Did you try setting "use only cookies" to true and then disabling cookies in
your browser?

--
+mrcakey
Re: session_start() should return FALSE but does not [message #170298 is a reply to message #170295] Wed, 27 October 2010 11:03 Go to previous messageGo to next message
alvaro.NOSPAMTHANX is currently offline  alvaro.NOSPAMTHANX
Messages: 277
Registered: September 2010
Karma: 0
Senior Member
El 27/10/2010 12:13, +mrcakey escribió/wrote:
> ""Álvaro G. Vicario""<alvaro(dot)NOSPAMTHANX(at)demogracia(dot)com(dot)invalid> wrote in
> message news:ia8tql$rb7$1(at)news(dot)eternal-september(dot)org...
>> El 27/10/2010 9:49, Rene escribió/wrote:
> <snip>
>> The manual page does not state what "successfully started" means. I've
>> been testing it myself in PHP/5.3.3 under Windows XP and I've been unable
>> to make it return FALSE. It returns TRUE when it starts a new session, it
>> returns TRUE when it resumes a previous session, it returns TRUE when
>> session_start() was already called, it returns TRUE when the session
>> directory does not exist... If there's a situation when it will eventually
>> return FALSE, I haven't been able to discover it.
>>
>
> Did you try setting "use only cookies" to true and then disabling cookies in
> your browser?

Good point. I've just tried and it returns TRUE. Of course, when you
think about it, it makes sense: PHP has no way to find out whether the
browser will accept the cookie or not.

(My guess is that it the feature works fine in Linux but I cannot test
it right now.)


--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--
Re: session_start() should return FALSE but does not [message #170299 is a reply to message #170294] Wed, 27 October 2010 12:37 Go to previous message
Rene[1] is currently offline  Rene[1]
Messages: 2
Registered: October 2010
Karma: 0
Junior Member
On 27 Okt., 12:10, "Álvaro G. Vicario"
<alvaro.NOSPAMTH...@demogracia.com.invalid> wrote:

> The manual page does not state what "successfully started" means. I've
> been testing it myself in PHP/5.3.3 under Windows XP and I've been
> unable to make it return FALSE.

Thanks for that feedback. I guess it's all about the meaning of
"success". Maybe it means that a session has been created on the
server which happens before any communication to the client takes
place.

Rene
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Study Abroad Scholarship For Study in Australia...
Next Topic: Biosphere Technology -
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Oct 20 10:02:05 GMT 2024

Total time taken to generate the page: 0.02920 seconds