Your Ad Here

Saturday, November 7, 2009

What is the difference between session_register and $_session?

Following are differences between session_register and $_SESSION

The very first main and simple difference is that session_register function returns boolean value and $_SESSION returns string value. The second will be session_register function doesn't work if register_global is disabled. But whereas $_SESSION works in both case whether register_global is disabled or enabled. So using $_SESSION for session variable manipulation is more appropriate.

$_SESSION (uppercase !)is a superglobal. You treat it like an associative array, and you can store your session variables in it. session_register() is used for register one or more global variables with the current session. session_register is old php-style for php < 4.4.x and may never used in conjunction with $_SESSION. While $_SESSION[] array is used for storing one or more variables with in the current session array. session_register() depends upon register_global is enable or disable, If it disable it will not work.
Reply With Quote

I read in some blog that using $_SESSION[var]=value is better than using session_register. It is because session_register() only works if register_globals is set ON in your php.ini file. Use $_SESSION , and don't forget to start the session since the strict beginning of the script (before session_start(), only include the classes definition if an instance is stored as a session variable.

No comments:

Post a Comment

Your Ad Here