MyBB Community Forums

Full Version: Using Forum Database for Other Parts of Site
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I'm not the most confident when it comes to php, and I'm paranoid about security issues. Hopefully, this can be understood Big Grin

I want a log in container on the rest of my site's pages, and I want to use the forum database.

The reason for this, is I don't want to show my registered members adverts, which is quite straightforward to do on the forum.

I do not want to bridge the various applications I'm using, though, as there really isn't any need.

In short:

How do I use the forums database for logging people in on any page of my site?

How do I only show ads to guests on the pages of my site?


Thanks for your help Smile
From other parts of your site just have your forum's global.php included. then you can use $mybb->user array for all the user info if they're logged in. To check if online you can do:
<?php
if($mybb->user['uid'] == 0){
echo "Guest!";
}else{
echo "logged in as ".$mybb->user['username'];
}

Then for the login form use:

<form action='forums/member.php' method='post'>
Username: <input type='text' name='username' size='25' maxlength='30' /><br />
Password: <input type='password' name='password' size='25' />
<input type='hidden' name='action' value='do_login'>
<input type='hidden' name='url' value='index.php' />
<input type='submit' class='submit' name='submit' value='Login' /></form><br>

EDIT: Make sure to edit the path to member.php Toungue
Also, make sure to have this php code beforew you include global.php:

define("IN_MYBB",1);
Thanks for the responses folks. I will give it a go Smile Is there anything I can duff up/need to be aware of security-wise?
Just make sure you sanitize any inputs, and use MyBB's database class if possible Smile
When you say sanitizing inputs, could you be a bit clearer Tom? I'm still new to php and a little paranoid about it Big Grin Cheers
If all you want is login integration just follow Booher's post.
Thanks Smile
(2011-11-16, 10:10 PM)coco_moco Wrote: [ -> ]When you say sanitizing inputs, could you be a bit clearer Tom? I'm still new to php and a little paranoid about it Big Grin Cheers

He means if something is supposed to be a number, then pass it through intval(), if it's a string do $db->escape().
If you are storing the content in a database you should also use htmlspecialchars_uni function.
Pages: 1 2