We help IT Professionals succeed at work.

Difference between 'session_register' and a $_SESSION variable?

tr5
tr5 asked
on
Hi
Can someone explain when to use session_register() versus using a session variable? What I mean is: Say a user successfully logs in, do I have to use:

session_register('username');
then use
if(session_is_registered('username'))
elsewhere to validate

or can I just create a regular session variable and set it to some value and use that to check whether a user logged in correctly?
$_SESSION['username'] = LOGGED_IN;
then use
if($_SESSION['username'] == LOGGED_IN)
elsewhere to validate

Thanks
tr5
Comment
Watch Question

Top Expert 2007
Commented:
session_register is old php-style for php < 4.4.x and may never used in conjunction with $_SESSION. See http://www.php.net/manual/en/function.session-register.php The new way is tu use session_start() and the access session variables via $_SESSION.
tr5

Author

Commented:
I ahve php 5. Are you saying I should remove from my code, this:
session_register('username');
.....
if(session_is_registered('username'))

and do something like this instead?
$_SESSION['username'] = LOGGED_IN;
.....
if(isset($_SESSION['username']) && $_SESSION['username'] == LOGGED_IN)
Top Expert 2007

Commented:
Yes, that how new PHP-code should look like.
tr5

Author

Commented:
Thank you

Explore More ContentExplore courses, solutions, and other research materials related to this topic.