Activity Stream
48,167 MEMBERS
6749 ONLINE
besthostingforums On YouTube Subscribe to our Newsletter besthostingforums On Twitter besthostingforums On Facebook besthostingforums On facebook groups

Results 1 to 2 of 2
  1.     
    #1
    Member
    Website's:
    litewarez.net litewarez.com triniwarez.com

    Default 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

    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
    1. Sessions stored on file
    2. 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();
        }
    }
    ?>
    ok so now as you can see from above we have several things we can do with sessions now
    • 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'
    and after:
    PHP Code: 
    include SYSTEM_BASE_PATH '/engine/Session.php'
    Ok lets add to the Registry system!

    Find:
    PHP Code: 
    Registry::set('Input', new Input()); 
    Add after:
    PHP Code: 
    Registry::set('Session', new Session()); 
    Ok thats it for sessions now... im sure by now you can understand how you would use it!

    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: 5
    Join 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


  2.   Sponsored Links

  3.     
    #2
    Member
    Website's:
    pspmafia.com zrev.net
    thanks again ur the best lol
    Trusted & Respected Members:
    ACiD | Narutoroot | JmZ | Jackson | Phamous | litewarez





Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 5
    Last Post: 19th Feb 2010, 06:38 PM
  2. Tutorial [Creating a PHP Framework] {advanced} (PART 4)
    By litewarez in forum Tutorials and Guides
    Replies: 1
    Last Post: 9th Feb 2010, 04:24 AM
  3. Tutorial [Creating a PHP Framework] {advanced} (PART 3)
    By litewarez in forum Tutorials and Guides
    Replies: 1
    Last Post: 4th Feb 2010, 02:12 AM
  4. Tutorial [Creating a PHP Framework] {advanced} (PART 2)
    By litewarez in forum Tutorials and Guides
    Replies: 2
    Last Post: 3rd Feb 2010, 05:37 AM
  5. Tutorial [Creating a PHP Framework] {advanced} (PART 1)
    By litewarez in forum Tutorials and Guides
    Replies: 1
    Last Post: 30th Jan 2010, 03:37 PM

Tags for this Thread

BE SOCIAL