View Single Post
  #8  
Old 03-14-2015, 07:10 PM
WeBBy WeBBy is offline
 
Join Date: Jun 2003
Posts: 43
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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(33126));
        }
    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 subscriptionsect). 

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.
Reply With Quote
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01272 seconds
  • Memory Usage 1,864KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD_SHOWPOST
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (6)bbcode_php
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)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)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • reputationlevel
  • showthread
Included Files:
  • ./showpost.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_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showpost_start
  • bbcode_fetch_tags
  • bbcode_create
  • postbit_factory
  • showpost_post
  • 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
  • showpost_complete