PHP - vBulletin - Get Current User

YouN00b / Articles

How to play a didgeridoo Modding your wii console
Submitted On: Thursday, November 12, 2009 at 2:39:23 PM
User Avatar
Toasty
Online Now

Please login to rate this submission.


Link to this Submission
Blog and Forum Link

HTML link
Facebook / Pagereaders

DO NOT ATTEMPT: Articles provided here are for INFORMATIONAL PURPOSES ONLY. DO NOT undertake any project based upon any information obtained on the internet, including this website. We are not responsible for, nor do we assume any liability for, damages resulting from the use of any information on this site. Please read the Legal page for more information.

PHP - vBulletin - Get Current User





Most web developers who plan to run a vBulletin site often times find the limited abilities of a just forum system, and the expense of keeping an active license, well, active, a bit irritating. With some PHP/MySQL wizardry, you can use this script to interact with the databases that drive the sessions of vBulletin. Do note, however, that this is just basic, and you will need to improve it if it does suit your needs.



Important to Note



ø vBulletin seems to monitor what sessions are active, and will remove these sessions from the database after they get so old. This script uses SQL's UPDATE statement to keep the timestamp updated, to keep you logged in.

ø This code cannot be 100% secure because it outputs mySQL errors directly to the screen. You may consider replacing it with file logging features (File Function Basics in PHP). This uses Perl Regular Expressions (preg_replace), which is supported in PHP 4 through 5. ereg_replace is depreciated as of PHP 5.3 and removed as of PHP6, so it is highly recommended to keep this setting.


<?PHP
function current_user()
     {
     $remip = $_SERVER['REMOTE_ADDR'];
     $cook = preg_replace("/[^a-zA-Z0-9]/i", "", $_COOKIE['bbsessionhash']);
     
     if ($cook!="")
          {
          if (!include('/path/to/vbulletin/forum/includes/config.php'))
               {
               echo "[mmtfunctions / current_user] Config.php could not be included.";
               die;
               }
          $CUQuery = mysql_connect($config['MasterServer']['servername'],$config['MasterServer']['username'],$config['MasterServer']['password']);
          if (!$CUQuery)
               {
               echo "[mmtfunctions / current_user] Cannot connect to database. " . mysql_error();
               die;
               }
          $CUResult = mysql_query("SELECT * FROM DatabaseName.session WHERE session.sessionhash = '" . $cook . "' AND session.host = '" . $remip . "' LIMIT 1;");
          if (!$CUResult)
               {
               echo "[mmtfunctions / current_user] Get User ID Database Error. " . mysql_error();
               die;
               }
          while ($row = mysql_fetch_array($CUResult))
               {
               $userid = $row['userid'];
               }
          IF ($userid!=0 and $userid!="")
               {
               $CUResult = mysql_query("SELECT * FROM DatabaseName.user WHERE userid = '" . $userid . "' LIMIT 1;");
               if (!$CUResult)
                  &nb...

 Member Only Area
Information Please Login or Join to read the rest of this submission.
Tags: PHP, vBulletin, Get, Current, User, web, development, integration, portal
  Friday, September 24th, 2010 at 6:02:37 AM #49160
PhiLep
PhiLep
Member
Level 4
Posts: 101
Submissions: 14
PhiLep is Offline

in inglish plz

Member Added Image
  Tuesday, March 27th, 2012 at 7:19:30 AM #55030
rajesh
rajesh
Member
Level 1
rajesh is Offline

Great work, it save my lots of timeMember Added Image