Topic: Cookies, Databases, Oh My!

Hey...congrats on PunBB, it's a really fantastic BBS...and I've tried a lot.

Now with the flattery out of the way...

Having a bit of trouble deciphering the cookie/database code for registered users.

I'm looking to add additional custom database entries(already done) that hold more specific and additional info for registered users.  For example, First name, Last name, categories their interested in, etc.

I've added these additional categories to the users database.

The major problem is in the cookie handling.  I admit I am a bit of newbie when it comes to cookies, the whole serialize, unserialize and list usage baffles me a bit.

Ok...so my question:

How do I have PunBB retreive an additional variable(say Last Name for example) from the DB, set it in a cookie, and then retrieve it for display or usage on the Status bar and elsewhere?

Thanks for the help...

-Paul

Re: Cookies, Databases, Oh My!

Well, you don't need to set it in a cookie. In the function check_cookie() in include/functions.php, all fields from the user database are retrieved and stored in the array $cur_user. So, if you wanted to output the last name in the status bar, you would simply echo out $cur_user['last_name'] or whatever the field is called.

"Programming is like sex: one mistake and you have to support it for the rest of your life."

Re: Cookies, Databases, Oh My!

Great...that simplifies things a lot.

However,  I'd like to display that info on other non-PunBB pages in the site as well.

Seems like the easiest way to do that would be with a cookie.

I could set a seperate cookie easily, but that seems too sloppy for my tastes.

I'd rather include that info with the cookie that PunBB sets.

Can you give me any pointers on how to set and extract that cookie info using the PunBB code?

Thanks again,

-Paul

Re: Cookies, Databases, Oh My!

Well, adding more stuff to the cookie is not so easy. You would have to edit the scripts that read and set cookies to handle your new elements in the array. A much simpler solution is to include the script common.php in your own scripts which will give you access to $cur_user. It's quite easy:

$pun_root = './forums/';
include $pun_root.'include/common.php';

$pun_root is the relative path to your forum root directory.

When you've done this, you can just echo out whatever you want from the $cur_user array. You also have access to an open database connection with $db and all other PunBB globals.

"Programming is like sex: one mistake and you have to support it for the rest of your life."

Re: Cookies, Databases, Oh My!

Yes, this looks like it will work fine...

Thanks again for your help and the great work...

Regards,

-Paul