miniBB ® 

miniBB

®
Support Forums
  
 | Start | Register | Search | Statistics | File Bank | Manual |
Master Class miniBB Support Forums / Master Class /  
 

How to Set Cookie for miniBB Authorization from external Script

 
Author coppercup
Partaker
#1 | Posted: 12 Oct 2005 00:36 
Here is how you can use your own login authorization script to set a cookie that MiniBB will recognize and use to automatically authorize the user within the forums as well:


First, check out this article:

https://www.minibb.com/synchronizing_minibb.html

You are specifically looking for how to set up your users database so that it can be shared between your own system and MiniBB. If you are building your own database and authorization, not all of the information in that article will be relevant, only the part about including the appropriate MiniBB fields in your database and storing passwords as MD5 hashes.

Assuming you have your database set up correctly, here are the steps to set a cookie that MiniBB will recognize.

Towards the top of your custom php login script, require the setup_options.php file:

require_once("forums/setup_options.php");

That allows you to access the various cookie parameters you should have set in the setup_options.php file when you installed MiniBB.

Next, you will need to include this function, which converts the password submitted by the user via your login form to an MD5 hash:

function writeUserPwd($pwd){
return md5($pwd);
}


Don't forget to actually pass the posted password to the function, and save the hash in a variable:

$hashed_pass = writeUserPwd($password);

Now, set the cookie expiration time:

$cookieexptime=time()+$cookie_expires;

Note that $cookie_expires is a variable set in the setup_options.php file.


Finally, (assuming that you have verified the user in whatever manner you choose for your own purposes,) set the cookie:

setcookie($cookiename, $username.'|'.$hashed_pass.'|'.$cookieexptime, $cookieexptime, $cookiepath, $cookiedomain, $cookiesecure);

Note that $cookiename, $cookiepath, $cookiedomain, and $cookiesecure are all variables set in setup_options.php. I suggest that the value for $cookiepath be set to "/", which allows all scripts at the root level in the html directory on the server to access the cookie.

If you use variable names other than $username or $password in your script to hold the username and password values, you will need to change the variable names in these lines of code.

It is also a wise idea to include a couple of lines in your logout script that deletes the cookie:

require_once("forums/setup_options.php");
setcookie($cookiename, "", time()-3600);


You may also want to dissable the login/logout stuff in MiniBB, since you are using your own authorization system. Look elsewhere in these forums for info about that.

Hope this helps someone.

Author Team
8-)
#2 | Posted: 12 Oct 2005 10:47 
Thanks! Hope, too.

Master Class miniBB Support Forums / Master Class /
 How to Set Cookie for miniBB Authorization from external Script
 Share Topic's Link

Your Reply Click this icon to move up to the quoted message


  ?
Post as a Guest, leaving the Password field blank. You could also enter a Guest name, if it's not taken by a member yet. Sign-in and post at once, or just sign-in, bypassing the message's text.


Before posting, make sure your message is compliant with forum rules; otherwise it could be locked or removed with no explanation.

 

 
miniBB Support Forums Powered by Forum Software miniBB ® Home  Features  Requirements  Demo  Download  Showcase  Gallery of Arts
Compiler  Premium Extensions  Premium Support  License  Contact Us
Get the Captcha add-on: protect your miniBB-forums from the automated spam and flood.


  ⇑