Topic: Why is my external login not working?
I have a growing site that has 100+ new sign ups a day and would really like to offer PunBB version 1.4 as my forum solution. I currently handle registrations and login via my site so I'd like to offer my users the ability to start posting once they've registered and logged in from the main site.
Are there examples of other sites that have done something similar or any docs that might point me in the right direction? I'm assuming I'll need to pre-populate the users table with the required info. After that do I create a session or cookie value to allow users to start posting?
ok, after playing with the code this is what I have so far. This block sits inside a private function I currently use to login.
if(!defined('FORUM_ROOT')) {
define('FORUM_ROOT', 'forum/');
}
global $forum_db;
require_once FORUM_ROOT.'config.php';
require_once FORUM_ROOT.'include/functions.php';
require_once FORUM_ROOT.'include/dblayer/common_db.php';
// username from my login and also exists in the forum DB
$username = $this->user;
$dbhost = 'localhost';
$dbuser = 'root';
$dbpasswd = 'password';
$dbname = 'forum';
$conn = mysql_connect($dbhost, $dbuser, $dbpasswd) or die ('Error connecting to mysql');
mysql_select_db("$dbname",$conn) or die ("could not open db".mysql_error());
$queryFromPunbb = "SELECT * FROM users WHERE username='$username'";
$result = mysql_query($queryFromPunbb, $conn) or die (mysql_error());
$forum_user= mysql_fetch_array($result) or die(mysql_error());
// I've verified that these are both returning valid values
$userId = $forum_user['id'];
$salt = $forum_user['salt'];
$password = $this->pass;
$hash = forum_hash($password, $salt);
$saveLogin = 0;
$expire = time()+60*60*24*30;
forum_setcookie($cookie_name, base64_encode($userId.'|'.$hash.'|'.$expire.'|'.sha1($salt.$hash.forum_hash($expire, $salt))), $expire);
cookie_login($forum_user);
Any idea what I'm missing or how to troubleshoot this further?
Thanks,
-Paul