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

Home » Imported messages » comp.lang.php » foreach in reverse
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: foreach in reverse [message #174186 is a reply to message #174180] Wed, 25 May 2011 06:19 Go to previous messageGo to previous message
Helmut Chang is currently offline  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
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: problem saving date fields
Next Topic: furniture
Goto Forum:
  

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

Current Time: Fri Nov 29 21:15:36 GMT 2024

Total time taken to generate the page: 0.04925 seconds