Results 1 to 2 of 2
-
10th Feb 2010, 10:45 AM #1OPMemberWebsite's:
litewarez.net litewarez.com triniwarez.comTutorial [Creating a PHP Framework] {advanced} (PART 5) - Sessions
Heya all!
Even tho this tutorial has not ahd the attention i felt it would im still going to continue !
Today were going to be talking about sessions!
Sessions are a way of storing information about the current user on the site, there mainly used to store stuff like user data etc
now sessions are mainly used for logins etc and are only valid for short amount of time aftyer the user has stopped browsing the site
if you notice when you login to a website and go away for 30-40 mins and come back your logged out, well this is due to the session expiring !
theres ways to autostart sessions again using cookies etc but were going to do the basic needed stuff first!
theres 2 ways we can buid sessions
- Sessions stored on file
- Sessions stored in database
First were going to build a session mask.. this will act just like the Input handler but for sessions, then at a later date we can look at the different ways to assign handlers so you can use different methods to stare sessions!
any way lets look at a simple image how sessions work
Ok so now as you can see the session handler is what were building today but soon we will build another class that controls how the data is stored! for now were just fetching and setting!
ok so let get started with some code!
PHP Code:<?php
class Session
{
//This will hold the session varaibles
public $data = array();
//Construct
public function __construct()
{
//make sure that session is not already active before we start it!
if(!session_id())
{
//Set up some basic session info
ini_set('session.use_cookies', 'On');
ini_set('session.use_trans_sid', 'Off');
session_set_cookie_params(0, '/');
//here we start session
session_start();
}
//here we use the operator =& so whenever session OR data is edited then both are affected
$this->data =& $_SESSION;
}
//Ok sets build a function to add data to the session
public function add($name,$value)
{
$this->data[$name] = $value; //can be object array string w.e
}
//This function will grab some data from session and if not exists then will return a var you specify else false
public function get($name,default = false)
{
return (isset($this->data[$name]) ? $this->data[$name] : false);
}
public function delete($name)
{
if(isset($this->data[$name]))
{
unset($this->data[$name]);
}
}
//ClearAll is good for logouts etc so it removes all active data from the session
public function clearAll()
{
$this->data = array();
}
}
?>
- Add
- Get
- Delete
- ClearAll (Delete)
these are basics for now!
Ok save to Save the file in /system/Session.php
lets add it to the startup.php and assign it to the Registry so lets get that out the way
Open the startup.php and find
PHP Code:include SYSTEM_BASE_PATH . '/engine/Input.php';
PHP Code:include SYSTEM_BASE_PATH . '/engine/Session.php';
Find:
PHP Code:Registry::set('Input', new Input());
PHP Code:Registry::set('Session', new Session());
When were finished with the framework we can build a script of your choice together for the community!litewarez Reviewed by litewarez on . Tutorial [Creating a PHP Framework] {advanced} (PART 5) - Sessions Heya all! Even tho this tutorial has not ahd the attention i felt it would im still going to continue ! Today were going to be talking about sessions! Sessions are a way of storing information about the current user on the site, there mainly used to store stuff like user data etc now sessions are mainly used for logins etc and are only valid for short amount of time aftyer the user has stopped browsing the site Rating: 5Join Litewarez.net today and become apart of the community.
Unique | Clean | Advanced (All with you in mind)
Downloads | Webmasters
Notifications,Forum,Chat,Community all at Litewarez Webmasters
-
12th Feb 2010, 03:06 PM #2MemberWebsite's:
pspmafia.com zrev.netthanks again ur the best lol
Trusted & Respected Members:
ACiD | Narutoroot | JmZ | Jackson | Phamous | litewarez
Sponsored Links
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
Tutorial [Creating a PHP Framework] {advanced} (PART 6) Smarty Engine
By litewarez in forum Tutorials and GuidesReplies: 5Last Post: 19th Feb 2010, 06:38 PM -
Tutorial [Creating a PHP Framework] {advanced} (PART 4)
By litewarez in forum Tutorials and GuidesReplies: 1Last Post: 9th Feb 2010, 04:24 AM -
Tutorial [Creating a PHP Framework] {advanced} (PART 3)
By litewarez in forum Tutorials and GuidesReplies: 1Last Post: 4th Feb 2010, 02:12 AM -
Tutorial [Creating a PHP Framework] {advanced} (PART 2)
By litewarez in forum Tutorials and GuidesReplies: 2Last Post: 3rd Feb 2010, 05:37 AM -
Tutorial [Creating a PHP Framework] {advanced} (PART 1)
By litewarez in forum Tutorials and GuidesReplies: 1Last Post: 30th Jan 2010, 03:37 PM
themaLeecher - leech and manage...
Version 5.02 released. Open older version (or...