After my last article about Session Management in PHP4, I got several
emails from people that had problems implementing what I tried to
describe. All theese emails had the same question:
Can you give me example code ? Yes, sure I can.
emails from people that had problems implementing what I tried to
describe. All theese emails had the same question:
Can you give me example code ? Yes, sure I can.
I will assume that you have read my previous article
(
it’s here in case you missed it). As I described earlier, you
have to tell PHP that the current page use session variables by
calling the
is called, you are free to register any variable that you have bound as
a session variable. This is done using the
function.
(
it’s here in case you missed it). As I described earlier, you
have to tell PHP that the current page use session variables by
calling the
session_start()
function. Once this functionis called, you are free to register any variable that you have bound as
a session variable. This is done using the
session_register()
function.
The first example (page1.php):
<?php
session_start
();
$my_session_variable = "some value";
session_register("my_session_variable");
?>
What this does is that it registers the variable
the variable will be alive (keep it’s value) across page-accesses, as
long as you call the
that need access to the
my_session_variable
as a session variable. This means thatthe variable will be alive (keep it’s value) across page-accesses, as
long as you call the
session_start()
function on all pagesthat need access to the
my_session_variable
variable.