Sessions in 4.2
Posted: Sun Oct 27, 2002 8:12 pm
Hey
Since I banged my head for a while figuring this out, I thought I'd pass it on in case someone else was having problems with sesssion handling in 4.2 This is outlined well in the online manual at http://www.php.net/
With register_globals off by default, use of the old session commands, such as
is no longer recommended, and in some cases may not work.
Instead, session info is now available via the superglobal array $_SESSION
To use sessions, you still need to begin each script with
To register a variable into the session, use
To access a session variable, refer to it with the same syntax
For example, this scriptlet sets a variable into the session and then prints it to the screen:
If you enter a variable into a session using session_register('variable name'), it will not be available in the $_SESSION array until the next time the session_start() command is issued. Variables added via the $_SESSION['variable name'] = 'value' method are available immediately.
Hope this helps someone out there.
Since I banged my head for a while figuring this out, I thought I'd pass it on in case someone else was having problems with sesssion handling in 4.2 This is outlined well in the online manual at http://www.php.net/
With register_globals off by default, use of the old session commands, such as
Code: Select all
session_register('variable name')
session_unregister('variable name')
session_is_registered('variable name')Instead, session info is now available via the superglobal array $_SESSION
To use sessions, you still need to begin each script with
Code: Select all
session_start()Code: Select all
$_SESSIONї'variable name'] = 'value you want to set';Code: Select all
$_SESSIONї'variable name']Code: Select all
<?php
session_start();
$user = 'Mack Owens';
$_SESSIONї'valid_user'] = $user;
echo $_SESSIONї'valid user'];
?>Hope this helps someone out there.