PDA

View Full Version : Integration with vBulletin - user session authication


mic2100
05-25-2007, 10:00 PM
hi,

I was trying to build a member area for my site and wanted to use the vbulliten login system for all the areas on my site, so I have written this code:



//this is the connection string to the database where the vbulliten table are.
require_once('../Connections/conn_nadea.php');

//this code will allow viewing of a page if a user is currently logged into the
//vbulletin forum and is not a guest user. if it detects that no user is logged
//in it will automatically send you to the forum home page where you can login
//or register as a new user.

$colname_rs_userid = "-1";
if (isset($_COOKIE['bbsessionhash'])) {
$sessionid = (get_magic_quotes_gpc()) ? $_COOKIE['bbsessionhash'] : addslashes($_COOKIE['bbsessionhash']);
}
mysql_select_db($database_conn_nadea, $conn_nadea);
$sql = sprintf("SELECT userid FROM session WHERE sessionhash = '%s'", $sessionid);
$rs_userid = mysql_query($sql, $conn_nadea);
$row = mysql_fetch_assoc($rs_userid);
$totalRows = mysql_num_rows($rs_userid);

if($totalRows == 0 and $row['userid'] == 0)
{

//this navigates to the forum login page
header('Location: ../forum/login.php');

mysql_free_result($rs_userid);

}
else
{

//this is where you page content should go.
echo "Page Content!!!";

mysql_free_result($rs_userid);

}


This will authicate any user that trys to access any page that you want protecting, if they are not currently logged into the forum then it will re-direct them to the forum. All you need to do is use this code at the top of the protected pages.

Hopfully this may be useful for somebody.

Robru
05-26-2007, 06:58 AM
Thanks for this solution :)

amnesia623
05-26-2007, 07:00 AM
uhh...yah it will be useful!!!

thanks!

Milad
05-26-2007, 02:39 PM
This can be done better by including gloabal.php in your file. I think.