Re: foreach in reverse [message #174186 is a reply to message #174180] |
Wed, 25 May 2011 06:19 |
Helmut Chang
Messages: 22 Registered: September 2010
Karma:
|
Junior Member |
|
|
Am 25.05.2011 02:43, schrieb Evolution:
> Also, I read somewhere that session_register() and session_start() are
> depricated and should not be used.
You should always consult the manual first for such questions:
<http://www.php.net/manual/en/function.session-register.php>
It's indeed deprecated since 5.3. It's the very, very "old" and
unsecure(?) way to register a variable in the session.
> However, when removed them, some
> code seems to have stopped working.
Yes, because on the other hand, session_start() is not deprecated, but
necessary to (aas the name indicates) start the session.
Again: consult the manual:
<http://www.php.net/manual/en/function.session-start.php>
> Below is an example of how I've
> been using session_register() and session_start(). What code would
> be proper here?
>
> session_register();
> session_start();
> $html_title="UCSB Earth Science : Home";
> $_SESSION['html_title'] = $html_title;
First: you should turn on error reporting. The above code should give at
least one warning, because session_register() expects at least one
parameter.
Second: trying to register a variable (what you don't in your usage of
session_register(), because you don't pass the name of a variable to
register) before you start the session...?
On the other hand, session_register() implicitly starts the session, if
none has been started already. So the following call of session_start()
would raise a notice, that the session already had been started.
And last: I wouldn't use the variable $html_title, if it's not needed
elsewhere in the code. It'sjust a tiny issue. But in this way, you
create a variable and in the next line, you create a copy of it in
assigning it to the session, while the original variable is not used
anymore.
So my opinion of a proper code here would be:
// Start the session:
session_start();
// Write data to the session:
$_SESSION['html_title'] = 'UCSB Earth Science : Home';
HTH, Helmut
|
|
|