?
Solved

Difference between 'session_register' and a $_SESSION variable?

Posted on 2008-01-28
4
Medium Priority
?
672 Views
Last Modified: 2012-06-27
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
0
Comment
Question by:tr5
  • 2
  • 2
4 Comments
 
LVL 48

Accepted Solution

by:
hernst42 earned 2000 total points
ID: 20758082
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.
0
 

Author Comment

by:tr5
ID: 20758123
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)
0
 
LVL 48

Expert Comment

by:hernst42
ID: 20758237
Yes, that how new PHP-code should look like.
0
 

Author Closing Comment

by:tr5
ID: 31425586
Thank you
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question