PDA

View Full Version : External Registration


dog199200
12-06-2011, 12:28 PM
Article URL: https://vborg.vbsupport.ru/showthread.php?t=82836&page=11&highlight=Create+New+User
Forum URL: http://www.forum.divineshadowsonline.com/
Forum Version: 4.1.8

I found this article a few days ago as I was looking for a way to use vB's internal registration system from an external page, but I keep getting a fatal error:

Fatal error: Registry object is not an object in [path]/includes/class_dm.php on line 205

Here's a slightly modified version of the code I found on the last page of the article:

Main Code
<?php
mysql_connect($DBhost, $DBuser, $DBpass) or die(mysql_error());
mysql_select_db($DBname) or die(mysql_error());

$RegAllowArray = mysql_query("SELECT * FROM setting WHERE varname = 'allowregistration'") or die(mysql_error());
$RegAllow = mysql_fetch_array($RegAllowArray);

$CountUserArray = mysql_query("SELECT COUNT(*) FROM user") or die(mysql_error());
$CountUser = mysql_num_rows($CountUserArray);

if($CountUser < 50)
{
if($RegAllow['value'] != 0)
{
function register_in_vb($username, $password, $email, $day, $month, $year)
{
define('VB_AREA', 'External');
define('SKIP_SESSIONCREATE', 0);
define('SKIP_USERINFO', 1);
require_once('/home/shininga/public_html/divineshadowsonline/forum/includes/init.php');
require_once('/home/shininga/public_html/divineshadowsonline/forum/includes/functions_misc.php');

$registry = $vbulletin;
unset($vbulletin);
$vbDb = $registry->db;
//declare as global vbulletin's registry and db objects
global $vbulletin,$db;
$vbulletin = $registry;
//backup the original $db object (new!!)
$backupdb = $db;
$db = $vbDb;

$newuser =& datamanager_init('User', $vbulletin, ERRTYPE_ARRAY);
$newuser->set('username', $username);
$newuser->set('email', $email);
$newuser->set('password', $password);
$newuser->set('usergroupid', 2);
$newuser->set('displaygroupid', 2);
$newuser->set('birthday', array($month, $day, $year));

$newuser->pre_save();

if(empty($newuser->errors)){
$db = $backupdb;
echo 1;
return $newuser->save();

}else{
$db = $backupdb;
echo 0;
print_r( $newuser->errors);
include("/home/shininga/public_html/divineshadowsonline/includes/register-form.php");
}
}

if(!$logged_in) {
if(isset($_POST['username']))
{
$key = $_POST['key'];
$username = $_POST['username'];
$password = $_POST['password'];
$confirmpass = $_POST['confirmpass'];
$day = $_POST['day'];
$month = $_POST['month'];
$year = $_POST['year'];
$email = $_POST['email'];
$tos = $_POST['tos'];
include("/home/shininga/public_html/divineshadowsonline/includes/register-functions.php");
$newuserid = register_in_vb($username, $password, $email, $day, $month, $year);

} else if(!isset($_POST['username'])) {
include("/home/shininga/public_html/divineshadowsonline/includes/register-form.php");
}
} else {
echo "<h4><center><b>You are already logged in!</b></center></h4>";
}
} else {
echo "<center>Registration Are Currently Disabled</center>";
}
} else {
echo "<center>Registration Are Currently Disabled</center>";
}
mysql_close();
?>

I could really use some help figuring out why i'm getting the error please. :P

--------------- Added 1323255563 at 1323255563 ---------------

Can anyone help me please? I really would rather use the internal systems to add users to the database so that everything runs through the error handle and stuff. It would be a royal pain in the but to rebuild every single one of the error handles in order to check if the information is valid.