A session class i wrote to learn more about classes. I think it's working good. And if there are any bugs, please post a comment. And don't kill me for the bad english explanation, am no native!
By : Dios
<?php /* Author: Stephan Six E-Mail: DiosV2@AOL.com / Dios@six-Design.de Homepage: http://www.six-design.de Last-Modified: 14.08.2003
HowToUse: Methods: $foo = new my_session([bool Session_starten]); <-- Declare a new object of the class. Use "new my_session(true)" to start a session. $foo->start(); <-- Start a session. $foo->session([Session_id]); <-- Gives you the session_id. If a session_id is passed to the method, a new session will be started, using the given session_id (See PHP-function: session_id()) $foo->stats(); <-- Shows you information about the environment. (PHP-version, reg_globals) $foo->clear(); <-- Ends a session $foo->test_cookies(); <-- Returns true if cookies are allowed, false if not. Needs to be executed before any output is displayed. Because the page, needs to be reloaded. $foo->show(); <-- Shows all variables in a session $foo->show_errors(); <-- Shows you an error-log. (To check if theres something wrong with the values, given to the set-method.) $foo->clear_errors(); <-- Clears the error-log (No real use, but anyway)
$foo->set(); <-- Registers a variable in a session. Values passed to the method, need to be: A pair (or a number of pairs) of "Name => Value", or an Array where the key will be used as the var-name and the value as the var-value.
Example: $test = "text"; is to be registerd:
objekt->set(VarName, VarValue); $foo->set("test", $test); (It's the same as: $foo->set("test", "text");) Another example: $foo->set("value1", 1, "value2", 4);
$foo->get(["_ARRAY"]); <-- Get a variable from a Session. If the string "_ARRAY" is passed, the method will return an Array with all session variables. Example: You want $x to have the value of the session-var $bar: var = objekt->get(SessionVarName); $x = $foo->get("bar"); */
class my_session{ var $rg; var $old; var $s_id; var $errors;
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.