user create bridge

Started by PHPLicengine, April 11, 2014, 05:28:41 AM

Previous topic - Next topic

PHPLicengine

If someone creates an account on our main website we want to create a smf account for them too. Does smf have an API or plugin or we should inject users directly to smf db? If yes what is smf password encryption format?

Kindred

Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Patey

I created a bridge similar to this by using the smf api to register the user if they aren't found in the smf db,

an example you can alter to your needs:

<?php
$user 
username variable;
$pass pass variable;

//smf query, leave as is unless you have different table names
$con=mysqli_connect("localhost","root","password","forum");
$sql "SELECT * FROM `smf_members` WHERE `member_name`='".$user."'";
$res mysqli_query($con$sql);

//your main site query, alter to your needs
$con2=mysqli_connect("localhost","root","weed45654","website");
$sql2 "SELECT * FROM `users` WHERE `username`='".$user."' AND `password`='".SHA1($pass)."'";
$res2 mysqli_query($con2$sql2);

//if user isn't in smf
if (mysqli_num_rows($res) == 0){
//if user isn't in your website db
if (mysqli_num_rows($res2) == 0){
echo "invalid login";
//otherwise do this
}else{
//register using smf api, using credentials given by user since they check out
$regOptions = array('member_name' => $user'password' => $pass);
smfapi_registerMember($regOptions);
//length of login, using remember me checkbox
if (isset($_POST['remember'])){
smfapi_login($user,9);
}else{
smfapi_login($user);
}
//send user to a page
header("Location: /forums/index.php");
}
}

//if user was in smf continue with an smf login, I used smf api but in hindsight ssi would've probably been better
if (smfapi_authenticate($user,$pass)== true){
//length of login, using remember me checkbox
if (isset($_POST['remember'])){
smfapi_login($user,9);
}else{
smfapi_login($user);
}
//send user to a page
header("Location: ".$_POST['loca']);
}

?>



Advertisement: