PDA

View Full Version : How can I use sessions for this?


AutomatikStudio
12-15-2003, 04:50 PM
Okay...I've got a game on my site that you would usually have to log in to...but what I want to do is make it so that once you've logged in to the forum you don't have to log into the game. I'm assuming you would use sessions but not sure how vBulletin's sessions work. Any input would rock face.

Forum: http://www.banterboards.com
Game: http://monsterslayer.banterboards.com

WannabeArtist
12-17-2003, 10:33 PM
Well, this *should* be pretty easy. Just do a session_start() at the beginning of your game's php script and match the session_id() with the session data in your forum's database.
I can only tell you how that should work on vB 3.0 as I don't have 2.3.3 set up.
<? php
session_start();
require('path_to_forum/includes/config.php');
mysql_connect($servername, $dbusername, $dbpassword);
mysql_select_db($dbname);
$userdata=mysql_query("SELECT * FROM session LEFT JOIN user ON(session.userid=user.userid) WHERE sessionhash='".session_id."'");
if ($userdata=mysql_fetch_array($userdata)) {
your game's php code where $userdata got all the info stored in an array
} else {
display login box
}
?>

Well, as long as your users go to the forum first and only after that to the ok, this should work. However, if they close all their browser windows and then go to that site it probably won't recognize them. Hope I was able to help out a bit, and good luck.

BTW, I *think* that simply including the global.php file of the forum does all of this and more automatically. If I'm able to remember correctly the data would be accessed through the array $bbuserinfo