By request:
The system we have is a full featured dynamic website in which vbb is only a small part. Membership in the main site is fee-based and it would be impractical to have 2 separate logins. So, on registration in the main site, all information gets logged into a database (temporary):
PHP Code:
$joindate = $_SERVER['REQUEST_TIME'];
$ip = $_SERVER['REMOTE_ADDR'];
$randomid = time();
//add to database
$db = mysql_connect("localhost", "username", "pass") or die ("Cannot connect to MySQL");
mysql_select_db("database",$db) or die ('Cannot Connect to Database');
$query = "insert into temporary (fname, lname, address, address2, city, state, zip, country, email, phone, iam, other, userid, password, joindate, ip, randomid, active)
values('$_POST[fname]','$_POST[lname]','$_POST[address1]','$_POST[address2]','$_POST[city]','$_POST[state]','$_POST[zip]','$_POST[country]','$_POST[email]','$_POST[phone]','$_POST[iam]','$_POST[other]','$_POST[nick]','$_POST[password]','$joindate','$ip', '$randomid','0')";
$result = mysql_query($query,$db) or die("<b>A fatal MySQL error occured in the Member Database</b>.\n<br>Error: (" . mysql_errno() . ") " . mysql_error());
User is then redirected to Paypal with random id:
PHP Code:
<input type="hidden" name="return" value="http://www.xxx.com/xxx.php?randomid=<? echo $_POST[randomid]; ?>">
<input type="hidden" name="cancel_return" value="http://www.xxx.com/xxx.php??randomid=<? echo $_POST[randomid]; ?>">
From Paypal (assuming completed payment and randomid returned )...
We transfer data into permanent database:
PHP Code:
//Get data from temporary database
$db = mysql_connect("localhost", "user", "pass") or die ("Cannot connect to MySQL");
mysql_select_db("dbname",$db);
$result = mysql_query("SELECT * FROM temporary WHERE randomid = '$_GET[randomid]'",$db);
while ($row = mysql_fetch_array($result)) {
extract($row);
}
//tranfer from Temp to Member database
mysql_select_db("database",$db) or die ('Cannot Connect to Member Database');
$query = "insert into members (fname, lname, address, address2, city, state, zip, country, email, phone, type, other, userid, password, joindate, ip, active)
values('$fname','$lname','$address1','$address2','$city','$state','$zip','$country','$email','$phone','$iam', '$other','$userid','$password','$joindate','$ip','1')";
$result = mysql_query($query,$db) or die("<b>A fatal MySQL error occured in the Member Database</b>.\n<br>Error: (" . mysql_errno() . ") " . mysql_error());
and temporary database deleted:
$db = mysql_connect("localhost", "user", "pass") or die ("Cannot connect to MySQL");
mysql_select_db("dbname",$db) or die ('Cannot Connect to vbb Database');
$result = mysql_query("DELETE FROM temporary WHERE userid='$username'",$db) or die ("<b>A fatal MySQL error occured deleting data from the temporary database</b>.\nError: (" . mysql_errno() . ") " . mysql_error());
Based on the original password entered above, we generate a vb compatible password (that we will also use for main site):
PHP Code:
//cleam some data and create some variables
$pass = $password;
unset ($password);
$username= $userid;
unset ($userid);
$passworddate = date(Y-m-d);
// Generate salt
function createSalt() {
$salt = '';
for ($i = 0; $i < 30; $i++) {
$salt .= chr(rand(33, 126));
}
return $salt;
}
//Generate password hash
function createPassword($password, $salt) {
return md5(md5($password) . $salt);
}
//clean salt
$salt=mysql_escape_string($salt);
$salt = createSalt();
$password = createPassword($pass, $salt);
We can then add the user to the vb user database:
PHP Code:
//Add to vbb database
$db = mysql_connect("localhost", "user", "pass") or die ("Cannot connect to MySQL");
mysql_select_db("vbb",$db) or die ('Cannot Connect to vbb Database');
$query = "insert into user (usergroupid, displaygroupid, username, password, passworddate, email, styleid, showvbcode, showbirthday, usertitle, customtitle, joindate, daysprune, reputation, reputationlevelid, pmpopup, avatarid, avatarrevision, profilepicrevision, sigpicrevision, options, notification_options, birthday_search, maxposts, ipaddress, referrerid, languageid, autosubscribe, pmtotal, pmunread, salt)
values('12','0','$username', '$password', '$passworddate', '$email', '0', '1', '2', 'CDI Member', '0', '$joindate', '0', '10', '5', '1', '0', '0', '0', '0', '45095252', '268435450', '0000-00-00', '-1', '$ip', '0', '1', '1', '0', '0', '$salt')";
$result = mysql_query($query,$db) or die("<b>A fatal MySQL error occured in the VBB database</b>.\nError: (" . mysql_errno() . ") " . mysql_error());
And add some custom field data:
PHP Code:
//Get vbb userid
mysql_select_db("vbb",$db);
$result = mysql_query("SELECT * FROM user WHERE username = '$username'",$db);
while ($row = mysql_fetch_array($result)) {
extract($row);
}
//Add Misc data to userfield
mysql_select_db("vbb",$db) or die ('Cannot Connect to vbb Database');
$query = "insert into userfield (userid, field2, field4)
values('$userid', '$city, $state', '$iam')";
$result = mysql_query($query,$db) or die("<b>A fatal MySQL error occured in the VBB database</b>.\nError: (" . mysql_errno() . ") " . mysql_error());
And any other information you may wish to add (like I add automatic subscriptions, ect).
I know that entereing data directly into the vbb database is strongly discouraged and that the code(s) above may not be the best or optimum, but auto-registration has long been sought in vbb and nobody has ever put one forth although I know they exist.
So, rather than critisize, maybe post the "proper" way to auto register AND autologin.
|