View Full Version : PHP help mirroring forum info


Liam19
Sun, September 4th, 2005, 11:57 PM
Hello there!
I'm doing some work with a forum and we're wanting to make a front page for the place. Just some basic info about what is going on with everything. What I want to do is have some user info on the front page.

I notice that thise site does exactly what I want to do.
Basically, I have registered on the forum as Liam19. When I visit the main john stone fitness site, it says "welcome back Liam19." I'm guessing that the page is doing some php magic and grabbing some info from the forum database then presenting it on the main page.

What I want to know is how is this done?
Any info or links to guides or anything would be great!
Thanks!

John Stone
Mon, September 5th, 2005, 07:16 AM
It's pretty easy. With vB, the user id information is stored in a cookie. You simply grab the cookie, extract the user id and then do a database query to get any additional information you need for that user. Here's what I did:


if (isset($_COOKIE['bbuserid']))
{
$userid = $_COOKIE['bbuserid'];
$conn = mysql_connect($hostname, $username,$password) or die("Unable to connect to database");
mysql_select_db("NAME_OF_YOUR_DATABASE",$conn) or die("Unable to select database");
$result = mysql_query("SELECT username FROM user WHERE userid=$userid",$conn);
$row = mysql_fetch_assoc($result);
extract($row);
}
else
{
$username="Guest";
}

Liam19
Mon, September 5th, 2005, 08:43 AM
That's excellent thanks.
I'm using IPB but I'm sure that'll help a lot.