PDA

View Full Version : 1 problem using alternative Registration


jstep
06-29-2008, 12:45 PM
I have a site and a forum, I would like to allow users to register at the site, and be automatically registered for the forum

As a matter of simplicity I would like to keep the databases seperate (they are both fairly large)

Right now here is my sql statement to register a new user

// date for entry
$date=date('y m d');
// IP ADRESS
#
$userIP = $_SERVER['HTTP_X_FORWARDED_FOR'];
if($userIP == "")
{
$userIP = $_SERVER['REMOTE_ADDR'];
}
// Get a salt
$salt = substr(md5(rand().rand()), 0, 3);
// work with password 2 here
$password2= md5(md5($password2).$salt);

$addvb= mysql_query("INSERT INTO `civclash_user` (`usergroupid`,`username`,`passworddate`,`password `, `email`, `ipaddress`, `salt`, `showvbcode`) VALUES ('2','$username', '$date', '$password2', '$email', '$userIP', '$salt', '1')");
if ($addvb){
echo "<br /> You were also added to the forum, see www.civclash.com/forums/index.php";
} else {
echo "You could not be added to the forum. Contact the administration.";
}

So essentially I am just making my registration form work for two different databases

Unfortunately (for some strange reason) when I add the new user, all their posts are listed as guest(it says their name, but lists them as guest, on the member list I can visit their profile and it shows them as a member). I can only think that it is because I forgot to add something to that query?

Sorry, I am decent at php, but by no means an expert

Any Help is greatly appreciated.

Thanks
Jstep

Dismounted
06-29-2008, 12:53 PM
There is more to just adding a row in the user table in registering a user in vBulletin. Use the datamanager, it will handle everything for you (once you feed it data).

jstep
06-29-2008, 01:09 PM
is there anywhere I can find a description of the datamanager?

and where is it in the code?

thanks for your help

edit: I reckon this should do it? https://vborg.vbsupport.ru/showthread.php?t=82836&highlight=datamanager

Dismounted
06-29-2008, 01:51 PM
<a href="http://www.vbulletin.com/docs/html/data_managers" target="_blank">Data Managers</a>

jstep
06-29-2008, 03:54 PM
<style type="text/css" media="all">
@import "style.css";
</style>
</head>

<body>

<?php include("header.php"); ?>

<div id="Header"><a href="./index.php" title="CivClash">CivClash</a></div>

<div id="Content">
<center><?
if ($gMode=="1"){
echo "<center>";
//checks if there trying to veriy there account
if(isset($_GET['verify'])) {
//gets the code and makes it safe
$code = addslashes($_GET['code']);
//gets the code from the database
$getcode=mysql_query("SELECT * FROM `verification` WHERE `code` = '$code'");
//counts the number of rows
$getcode = mysql_num_rows($getcode);
//if the ammount of rows is 0 the code does not exist
if($getcode == 0) {
echo "Invalid verification code!";
}
//or if the code does exist we will activiate there account
else{
//get the data from the database
$getcode=mysql_query("SELECT * FROM `verification` WHERE `code` = '$code'");
//fetchs the data from the db
$dat = mysql_fetch_array($getcode);
//sets the users user level to 2 which means they can now use there account
$update = mysql_query("UPDATE `members` SET `userlevel` = '2' WHERE `username` = '".$dat['username']."'") or die(mysql_error());
//deletes the code as there is no use of it now
$delete = mysql_query("DELETE FROM `verification` WHERE code = '$code'");
//says thanks and your account is ready for use
echo "Thank you, Your account has been verified.";
}
}else
//if we have posted the register for we will register this user
if(isset($_GET['register'])) {
//check to see if any fields were left blank
if((!$_POST[username]) || (!$_POST[password]) || (!$_POST[cpassword]) || (!$_POST[email])) {
echo "A field was left blank please go back and try again.";
}else{
//posts all the data from the register form
$username = $_POST[username];
$password = $_POST[password];
$cpassword = $_POST[cpassword];
$email = $_POST[email];
//check see if the 2 passwords are the same
if($password == $cpassword)
{
// Save as alternative to be used with vbulletin
$password2= $password;
//encrypts the password 8 times
$password = sha1(md5(md5(sha1(md5(sha1(sha1(md5($password))))) )));
$cname = mysql_query("SELECT `username` FROM `members` WHERE `username` = '$username'");
$cname= mysql_num_rows($cname);
//checks to see if the username or email already exist
if($cname>=1) {
echo "The username is already in use";
}else{

// Add the user to Vbulletin
define('THIS_SCRIPT', '../forumadd.php');
chdir('forums/');
require_once('./global.php');
require_once('./includes/class_dm.php');
require_once('./includes/class_dm_user.php');
$userdm = new vB_DataManager_User($vbulletin, ERRTYPE_ARRAY);

$userdm->set('username', $username);
$userdm->set('email', $email);
$userdm->set('password', $password);
$userdm->set('usergroupid',$usergroupid);
$userdm->set('ipaddress', $ipaddress);
$userdm->set('timezoneoffset', $timezoneoffset);
$userdm->set_bitfield('options', 'adminemail', '1');
$userdm->set_bitfield('options', 'showemail', '1');

#If there are errors (eMail not set, eMail banned, Username taken, etc.) you can check for errors using
if (count($userdm->errors)) {
for($i=0; $i<count($userdm->errors); $i++) {
print "ERROR{$i}:{$userdm->errors[$i]}\n";
}
}
else{
# If everything is OK
$newuserid = $userdm->save();
}
chdir('..');


getting headers already sent error? any idea what I need to change?

Unable to add cookies, header already sent.
File: /usr/home/civclash/public_html/register.php
Line: 10

Line 10=<style type="text/css" media="all">

MoT3rror
06-29-2008, 05:42 PM
You can't output anything before including vBulletin.

jstep
06-29-2008, 08:49 PM
i fixed this by having a

echo "You will now be registered for the forum.";
echo "<meta http-equiv='Refresh' content='2; URL=./forums/forumadd.php?username=$username&password=$password2&email=$email'/>";

and then the forumadd handles everything else

Now if I can just make it so you can't just add in anything in those $_GET variables to create a new account

eclectus
06-30-2008, 12:38 PM
you could echo out a form with hidden fields, and then do form.submit() at the end, it will forward the form with POST so nothing is exposed

Dismounted
07-01-2008, 07:04 AM
Using form.submit() will not work if Javascript is disabled.