I've just tried to do the same thing for my own site, if I understand correctly; you want to use the login system for your main website to 'automatically' log people in to the punBB forum... Ie, use the main site's user validation system instead of punBB's?
I modified my functions.php file so that the function check_cookie() looks like: (sorry, I used quote instead of code so I could highlight some bits)
function check_cookie(&$pun_user)
{
global $db, $db_type, $pun_config, $cookie_name, $cookie_seed;
$now = time();
$expire = $now + 31536000; // The cookie expires after a year
//// We assume it's a guest
//$cookie = array('user_id' => 1, 'password_hash' => 'Guest');
// If a cookie is set, we get the user_id and password hash from it
//if (isset($_COOKIE[$cookie_name])) {
// list($cookie['user_id'], $cookie['password_hash']) = @unserialize($_COOKIE[$cookie_name]);
//}
//if ($cookie['user_id'] > 1)
if (userIsLoggedIn() > 100)
{
// Check if there's a user with the user ID and password hash from the cookie
$result = $db->query('SELECT u.*, g.*, o.logged, o.idle FROM '
.$db->prefix.'users AS u INNER JOIN '
.$db->prefix.'groups AS g ON u.group_id=g.g_id LEFT JOIN '
.$db->prefix.'online AS o ON o.user_id=u.id WHERE u.id='
.intval(CURRENT_USER_FORUMID)) or error('Unable to fetch user information', __FILE__, __LINE__, $db->error());
$pun_user = $db->fetch_assoc($result);
//if (!isset($pun_user['id']) || md5($cookie_seed.$pun_user['password']) !== $cookie['password_hash'])
//{
// pun_setcookie(1, md5(uniqid(rand(), true)), $expire);
// set_default_user();
// return;
//}
The bits in bold are the bits I modified. userIsLoggedIn() is a function in my login system that check the user is logged in, and populates some constants to useful user info. It returns a code that specifies the user level, so my check > 100 means that the user is present and logged in, with the correct permissions.
I replaced part of the sql statement so that instead of getting the punBB user id from a cookie, it gets it from some data read from my own website's user table in my userIsLoggedIn() function. Basically when I register a new user, I automatically add a user record to the punBB database, and then add that (forum) user id to a special field in my own website user table, which I read out again in userIsLoggedIn().
Then notice I remove the later check leading to set_default_user() since it's unecessary since I've already validated that the user is ok by that point.
This seems to work ok so far, and you never need worry about creating cookies?...
Edit: This was with v. 1.2.17, btw...