Re: [Q] session variables wouldn't keep contents.
| From: | Yasuo Ohgaki | Date: | Tue, 13 Mar 2001 07:24:57 +0000 |
| Subject: | Re: [Q] session variables wouldn't keep contents. | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-43630@lists.php.net to get a copy of this message | ||
----- Original Message -----
From: "Chung Ha-Nyung" <alita@kldp.org>
To: <php-general@lists.php.net>
Sent: Tuesday, March 13, 2001 3:19 PM
Subject: [PHP] [Q] session variables wouldn't keep contents.
>
> Hi guys,
>
> Some php programs doesn't seem to work normally in a certain
> server. Those wokred correctly in my Debian box.
> Session is the problem.
The code seems wrong. Although, it can work. It depends on php.ini.
>
> It seems that the contents of session variables disappears after
> reloading the php page. Here is the program.
>
> ---- test.php ----
> <html>
> <body>
> <?php
> session_start();
You must start session before output anything to browser, or you must use
buffering to do this,
or you must use URL mode for session.
i.e. This code sends "<html><body>" before starting session and cookie header
must be sent before if session is cookie mode.
I recommend to write session_start() before programmers do anything.
> if(!session_is_registered("name")) {
> echo "session is not registered<br><br>";
> session_register("name");
> $HTTP_SESSION_VARS["name"] = "test";
> echo "newly registered<br><br>";
> }
> $session_name = $HTTP_SESSION_VARS["name"];
> echo session_encode()."<br><br>";
> echo "session_name = $session_name";
> ?>
> </body>
> </html>
> ---- test.php ----
>
> Can I handle it with only php configuration file? Or Do I have to
> modify my php programs?
I'm not sure what do you want to handle "it".
Starting session can handle in php.ini and inside code.
>
> In addition to this, I have a few questions about the work of session
> in php 4.0.4
>
> Q1) Do I have to use session_start() explicitly although session.auto_start
> is set to 1 in php.ini?
No.
Session will be started automatically, so programmer does not have to write it.
I recommend to write session_start(), though.
Also, session will be started implicitly if programmer uses session functions
even without setting session.auto_start to true. It should work, if programmer
didn't send any output to browser before. i.e. Programmer does not even have to
write session_start() even if session.auto_start is false. I don't recommend it,
though.
> Q2) Do I have to use session_register("variable_name")?
> In my Debian woody box, it seems to run well without it.
It seems works fine on my box without it when I use $HTTP_SESSION_VARS at least.
I think it will not work without $HTTP_SESSION_VARS.
(PHP4.0.4pl1/Apache/RedHat Linux7)
Regards,
--
Yasuo Ohgaki
>
> Regards,
>
> --
> Chung Ha-Nyung <alita@kldp.org>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>
>