English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I'm trying to create a session class so that I can manage the session as an object and I can pass that object around to other class function.

But in my constructor of my session class how to I set the session as my class instance?

Example:

class Session {
var $session;

function __construct($tmp_session) {
$session = $tmp_session;
}
//..... other code and function

?>

Then on the page I've this.....

require 'session.php';
session_start();
$session = new Session($_SESSION);

}

Will that work? I just try it and it seems doesn't work. Any idea?

2007-05-17 09:01:07 · 1 answers · asked by Michael C 1 in Computers & Internet Programming & Design

1 answers

Try declaring and using session variables. For example, if you want to pass the userid from page to page, you would use something like:

Put session_start(); inside of a file called session.php.

require ('session.php');
$_SESSION['userid'] = 'janedoe';
?>

Then anywhere else on the page, just use something like:

echo $_SESSION['userid'];

Your output would be: janedoe

2007-05-17 09:10:36 · answer #1 · answered by Jen 2 · 0 0

fedest.com, questions and answers