Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 12-05-2010, 02:20 PM
tguillea tguillea is offline
 
Join Date: Nov 2010
Posts: 2
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default SOLUTION - VBulletin 4 External, Manual Member Signup/Registration/Login + Cookies

This is a solution to this problem, NOT a question.

Apparently all the serious forum posters here don't understand something - there is no VB4 solution to this. I've read dozens of posts with no replies, few replies, and simply lazy replies, with people telling the poster to search through the articles and never posting links... so a big F-U to those guys.

I know the whole vbDatabaseManager thing would make this cleaner, but this is to authenticate a VB4 login from another, external form, which is unrelated to vbulletin (except for the member's accounts that are linked). I don't like the idea of vbulletin handling my errors, redirects, etc. so I made a manual / "forced" way to do this.

Anyways, here is my solution - note the following: the table prefix is "vb_", cookie prefix is "bb_", COOKIE_SALT = "4j2klj5lk2jklj23mlk6j2klj4klj2", and the forum is installed in "/inside/forums/". You can find the COOKIE_SALT on line 34 of /includes/functions.php

PHP Code:
//$password is already MD5'd once, so replace "$password" with md5($_POST['password']) where applicable
/*insert user into table*/
function fetch_user_salt($length 30){
    
$salt '';
    for (
$i 0$i $length$i++){
        
$salt .= chr(rand(33126));
       }
    return 
mysql_real_escape_string($salt);
    }
$vb_salt fetch_user_salt();
$passdate date('Y-m-d');
$password_salted md5($password.$vb_salt);
$cookie_password_salted md5(md5($password.$vb_salt).'4j2klj5lk2jklj23mlk6j2klj4klj2');

/*USED ONLY WHEN LOGGING IN AND NOT SIGNING UP
$result_salt = mysql_query("SELECT `salt` FROM `vb_user` WHERE `userid`='$userid' LIMIT 1");
$row_salt = mysql_fetch_array($result_salt);
$vb_salt = $row_salt['salt'];
*/

$row_title mysql_fetch_array(mysql_query("SELECT * FROM `vb_usertitle` ORDER BY `usertitleid` ASC LIMIT 1"));
$usertitle $row_title['title']; //get the default first title

mysql_query("INSERT INTO `vb_user` (`userid`, `usergroupid`, `membergroupids`, `displaygroupid`, `username`, `password`, `passworddate`, `email`, `styleid`, `parentemail`, `homepage`, `icq`, `aim`, `yahoo`, `msn`, `skype`, `showvbcode`, `showbirthday`, `usertitle`, `customtitle`, `joindate`, `daysprune`, `lastvisit`, `lastactivity`, `lastpost`, `lastpostid`, `posts`, `reputation`, `reputationlevelid`, `timezoneoffset`, `pmpopup`, `avatarid`, `avatarrevision`, `profilepicrevision`, `sigpicrevision`, `options`, `birthday`, `birthday_search`, `maxposts`, `startofweek`, `ipaddress`, `referrerid`, `languageid`, `emailstamp`, `threadedmode`, `autosubscribe`, `pmtotal`, `pmunread`, `salt`, `ipoints`, `infractions`, `warnings`, `infractiongroupids`, `infractiongroupid`, `adminoptions`, `profilevisits`, `friendcount`, `friendreqcount`, `vmunreadcount`, `vmmoderatedcount`, `socgroupinvitecount`, `socgroupreqcount`, `pcunreadcount`, `pcmoderatedcount`, `gmmoderatedcount`, `assetposthash`, `fbuserid`, `fbjoindate`, `fbname`, `logintype`, `fbaccesstoken`, `bloggroupreqcount`, `showblogcss`) VALUES ('$userid', '2', '', '0', '$username', '$password_salted', '$passdate', '$email', '0', '', '', '', '', '', '', '', '1', '0', '$usertitle', '0', '$timestamp', '0', '$timestamp', '$timestamp', '0', '0', '0', '10', '5', '0', '0', '0', '0', '0', '0', '3163223', '', '0000-00-00', '-1', '-1', '$ip', '0', '1', '0', '0', '-1', '0', '0', '$vb_salt', '0', '0', '0', '', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '', '', '0', '', 'vb', '', '0', '1')") or die(mysql_error());

mysql_query("INSERT INTO `vb_usertextfield` (`userid`) VALUES ('$userid')") or die(mysql_error());
mysql_query("INSERT INTO `vb_userfield` (`userid`) VALUES ('$userid')") or die(mysql_error());

require(
'getrealip.php');
function 
fetch_substr_ip($ip$length null){
    if (
$length === null OR $length 3){
        
$length 1;
        }
    return 
implode('.'array_slice(explode('.'$ip), 0$length));
    }
$alt_ip fetch_substr_ip(fetch_alt_ip());
$timestamp time();
$user_agent $_SERVER['HTTP_USER_AGENT'];
$idhash md5($_SERVER['HTTP_USER_AGENT'].$alt_ip);
$sessionhash md5(uniqid(microtime(), true));
//delete old sessions - a crude but useable method
mysql_query("DELETE FROM `vb_session` WHERE `userid`='$userid' OR `host`='$ip'") or die(mysql_error());
//insert new session
mysql_query("INSERT INTO `vb_session` (`sessionhash`, `userid`, `host`, `idhash`, `lastactivity`, `location`, `useragent`, `styleid`, `languageid`, `loggedin`, `inforum`, `inthread`, `incalendar`, `badlocation`, `bypass`, `profileupdate`) VALUES ('$sessionhash', '$userid', '$alt_ip', '$idhash', '$timestamp', '/inside/forums/forum.php', '$user_agent', '0', '0', '1', '0', '0', '0', '0', '0', '0')") or die(mysql_error());
//add cookies to link user to session
setcookie('bb_lastvisit',$timestamp);
setcookie('bb_lastactivity',0);
setcookie('bb_sessionhash',$sessionhash);
setcookie('bb_userid',$userid);
setcookie('bb_password',$cookie_password_salted); 
And here is the included file, getrealip.php
PHP Code:
<?php

/**
* Fetches an alternate IP address of the current visitor, attempting to detect proxies etc.
*
* @return    string
*/
function fetch_alt_ip(){
    
$alt_ip $_SERVER['REMOTE_ADDR'];

    if (isset(
$_SERVER['HTTP_CLIENT_IP']))
    {
        
$alt_ip $_SERVER['HTTP_CLIENT_IP'];
    }
    else if (isset(
$_SERVER['HTTP_X_FORWARDED_FOR']) AND preg_match_all('#\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}#s'$_SERVER['HTTP_X_FORWARDED_FOR'], $matches))
    {
        
// try to avoid using an internal IP address, its probably a proxy
        
$ranges = array(
            
'10.0.0.0/8' => array(ip2long('10.0.0.0'), ip2long('10.255.255.255')),
            
'127.0.0.0/8' => array(ip2long('127.0.0.0'), ip2long('127.255.255.255')),
            
'169.254.0.0/16' => array(ip2long('169.254.0.0'), ip2long('169.254.255.255')),
            
'172.16.0.0/12' => array(ip2long('172.16.0.0'), ip2long('172.31.255.255')),
            
'192.168.0.0/16' => array(ip2long('192.168.0.0'), ip2long('192.168.255.255')),
        );
        foreach (
$matches[0] AS $ip)
        {
            
$ip_long ip2long($ip);
            if (
$ip_long === false)
            {
                continue;
            }

            
$private_ip false;
            foreach (
$ranges AS $range)
            {
                if (
$ip_long >= $range[0] AND $ip_long <= $range[1])
                {
                    
$private_ip true;
                    break;
                }
            }

            if (!
$private_ip)
            {
                
$alt_ip $ip;
                break;
            }
        }
    }
    else if (isset(
$_SERVER['HTTP_FROM']))
    {
        
$alt_ip $_SERVER['HTTP_FROM'];
    }

    return 
$alt_ip;
}
?>

Just make sure to connect to the database before this code and it should work great. Any problems, shoot me a message
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:24 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03512 seconds
  • Memory Usage 2,279KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (2)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)showthread_list
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_threadedmode.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids_threaded
  • showthread_threaded_construct_link
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete