Public paste
LogInToSession
By: fruffl | Date: Nov 15 2009 17:06 | Format: PHP | Expires: never | Size: 2.08 KB | Hits: 902

  1. <?php
  2.  
  3.     class FRUFFL_SESSION
  4.     {
  5.  
  6.       const vc                                    = 1000;
  7.       const cn                                    = "fruffl_session";
  8.      
  9.      
  10.       protected $ip                               = null;
  11.       protected $agent                            = null;
  12.       protected $location                         = null;
  13.       protected $lockey                           = null;
  14.       protected $loc                              = null;
  15.       protected $token                            = null;
  16.  
  17.  
  18.  
  19.  
  20.       public static function
  21.       class_info
  22.       ()
  23.       {
  24.      
  25.               return array(self::vc, self::cn);
  26.      
  27.       }
  28.      
  29.      
  30.       public function
  31.       __CONSTRUCT
  32.       ()
  33.       {
  34.      
  35.               $this->ip          = $_SERVER['REMOTE_ADDR'];
  36.               $this->agent       = $_SERVER['HTTP_USER_AGENT'];  
  37.               $this->location    = __LOCATION__;
  38.               $this->lockey      = dirname(__SCRIPT__)."/".__LOCATION__;
  39.               $this->loc         = md5($this->lockey);
  40.               $this->token       = md5(uniqid(rand(), true));
  41.              
  42.               $this->save_token();
  43.      
  44.       }
  45.  
  46.  
  47.       public function
  48.       save_token
  49.       ()
  50.       {
  51.      
  52.               $_SESSION['TOKEN'][$this->loc] = $this->token;
  53.      
  54.       }
  55.      
  56.  
  57.       public function
  58.       get_token
  59.       ()
  60.       {
  61.      
  62.               return $_SESSION['TOKEN'][$this->loc];
  63.      
  64.       }
  65.      
  66.      
  67.       public function
  68.       compare_token
  69.       ($t)
  70.       {
  71.      
  72.               if($t == $_SESSION['TOKEN'][$this->loc]) return true;
  73.      
  74.       }
  75.  
  76.  
  77.       public function
  78.       log_in($user_id)
  79.       {              
  80.               if(class_exists('DB_BRIDGE'))
  81.               {
  82.                 $DB_BRIDGE = new DB_BRIDGE;
  83.                  
  84.                 if($user = $DB_BRIDGE->loadData('_authors', $user_id))
  85.                   print_r($user);
  86.                  
  87.               }
  88.               else
  89.               {
  90.                 return false;
  91.               }
  92.       }
  93. ?>