Welcome Guest, Not a member yet? Register   Sign In
vbulletin session/user integration into your Codeigniter framework
#1

[eluser]Unknown[/eluser]
Here is a very simple method to integrate vbulletin session and users into your codeigniter framework. And I am not using any vbulletin files which tend to change all the time from releases to releases.

If you don't want to load all the things vbulletin loads when it starts, you can just hook into vbulletin's cookie/session and get userinfo from there!

This should work in most of the vbulletin version. Works perfectly on vbulletin 4.2.0.

This is not complete but you get the idea now!

This file: model/session.php
Code:
class Session extends CI_Model {
function fetch_userid(){
  
  if ($userid = intval($this->input->cookie('bb_userid', true)) && $password = $this->input->cookie('bb_password', true)){
  
   $q = $this->db->query("SELECT userid, password FROM " . VBP . "user WHERE userid = " . $this->db->escape($userid) . " LIMIT 1");
    
   if ($q->num_rows() > 0) {
    
    $user = $q->row_array();    
    
    if(md5($user['password'] . VB_SALT) == $password){
    
     return $user['userid'];
    }
   }
  }
  
  if($sessionhash = $this->input->cookie('bb_sessionhash', true)){
  
   $q = $this->db->query('SELECT * FROM ' . VBP . 'session WHERE sessionhash = ' . $this->db->escape($sessionhash) . ' ORDER BY lastactivity DESC LIMIT 1');
  
   if ($q->num_rows() > 0) {
    
    $ip = implode('.', array_slice(explode('.', $this->input->ip_address()), 0, 4 - 1));
    $newidhash = md5($this->input->user_agent() . $ip);
    
    $session = $q->row_array();
    
    if ($session['idhash'] == $newidhash && (time() - $session['lastactivity']) < 900) {
    
     return $session['userid'];
    }
   }
  }
  
  return false;
}
}

You can find vb salt in the function file.

Put above code in model folder. I named mine initialize.php:

This file: model/initialize.php
Code:
define('VBP', 'vbulletin table prefix here');
define('VB_SALT', 'vbulletin salt key in vb function file');

$this->load->model('session');

$this->userid = $this->session->fetch_userid();

This file: controller/test.php
Code:
class Test extends CI_Controller {

var $registry = null;

var $uinfo = null;

function __construct() {
  parent::__construct();
  require_once( APPPATH .'models/initialize.php');

}

function index() {

}
}


if you want to insert your own session record and cookie then use this to generate vbulletin sessionhash key:

Code:
$sessionhash = md5(uniqid(microtime(), true)); //to fetch sessionhash






Theme © iAndrew 2016 - Forum software by © MyBB