Connecting forum board accounts to front page of my website

  • StonerLifestyle
  • Newbie
  • Newbie
  • No Avatar
  • Joined: Mar 14, 2012
  • Posts: 11
  • Status: Offline

Post March 14th, 2012, 8:20 pm

Hey guys. I am looking to get my forum board at my website working together with the main site. I would like for the user to have the option to login on the main site, not just on the forums. I would like to go further and be able to feature a lastest threads section on the home page of the main site (not the home page of the forums).

I am running phpbb3 for the forums on my website. I am familiar to non-web programming alot more than web programming, but I believe I am fully capable of reading up on how I can do this and implement it on my website.

Can someone point me in the right direction? This would be a purely php job I am assuming? And also if someone knows of a general guide for this sort of thing a link would be wonderful.

Thanks for all advice guys, really appreciate it.

EDIT - Thanks for the current help all, heres what I currently am trying to do with this site...

Basically I would like my home page to do the following:
1 - Check to see if the visitor on the home page is logged into the forums
2 - If yes, display this information on the home page
3 - If no, display that the visitor is not logged in the forums on the home page
4 - Provide a log in box and register link on the home page for the forums (Already have this done thanks to natas :D )
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post March 14th, 2012, 8:20 pm

  • natas
  • PHP Ninja
  • Proficient
  • No Avatar
  • Joined: Mar 28, 2009
  • Posts: 305
  • Loc: AFK
  • Status: Offline

Post March 14th, 2012, 8:54 pm

Here's the code I use for one of my sites, maybe you can use it as rough guide.

EDIT: This just allows users to register from a "home" page of your site away from the forums and automatically register for the forums.

Code: [ Select ]
{
    // username and password and email sent from form
    $username=$_POST['username'];
    $password=$_POST['password'];
    $user_email=$_POST['email'];
    
    // CHECK YOUR $_POST VARIABLES TO MAKE SURE THEY'RE VALID.
    
    if ($tests==false) // TOTALLY GENERIC, YOU WILL HAVE TO RUN YOUR OWN TESTS
    {
        header("location: error.php");
    }
    else    
    {
        // PHPBB requires this so it doesn't kick you out of the pages or produce an error
        define('IN_PHPBB', true);
        $phpbb_root_path = 'forums/';
        $phpEx = substr(strrchr(__FILE__, '.'), 1);
        include($phpbb_root_path . 'common.php');
        include($phpbb_root_path . 'includes/functions_user.php');
        include($phpbb_root_path . 'includes/ucp/ucp_register.php');


        // Forum Database Variables
        $host="yourhost.yourhostdomain.com"; // Host name
        $dbusername="username"; // Mysql username
        $dbpassword="databasepassword"; // Mysql password
        $db_name="databasename"; // Database name
        $users_tbl="phpbb_users"; // Table name for PHPBB Users
        $group_tbl="phpbb_user_group"; // Table Name for PHPBB Groups

        // Connect to server and select database
        mysql_connect("$host", "$dbusername", "$dbpassword")or die("cannot connect");
        mysql_select_db("$db_name")or die("cannot select DB");

        // A check to see if the username is unique
        $sql="SELECT * FROM $users_tbl WHERE username='$username'";
        $result=mysql_query($sql);
        $count=mysql_num_rows($result);
    
        // A check to see if the email is unique
        $sql2="SELECT * FROM $users_tbl WHERE user_email='$user_email'";
        $result2=mysql_query($sql2);
        $count2=mysql_num_rows($result2);

        if($count==1)
        {
            header("location: error.php");
        }
        elseif($count2==1)
        {
            header("location: error.php");
        }
        else
        {

    $sql_ary = array(
      'username'     => $username,
      'username_clean'  => $username_clean,
      'user_password'   => phpbb_hash($password),
      'user_pass_convert' => 0,
      'user_email'    => $user_email,
      'user_email_hash'  => crc32(strtolower($user_email)) . strlen($user_email),
      'group_id'     => 2,
      'user_type'     => 0,
    );
  user_add($sql_ary);
        }
    }
}
  1. {
  2.     // username and password and email sent from form
  3.     $username=$_POST['username'];
  4.     $password=$_POST['password'];
  5.     $user_email=$_POST['email'];
  6.     
  7.     // CHECK YOUR $_POST VARIABLES TO MAKE SURE THEY'RE VALID.
  8.     
  9.     if ($tests==false) // TOTALLY GENERIC, YOU WILL HAVE TO RUN YOUR OWN TESTS
  10.     {
  11.         header("location: error.php");
  12.     }
  13.     else    
  14.     {
  15.         // PHPBB requires this so it doesn't kick you out of the pages or produce an error
  16.         define('IN_PHPBB', true);
  17.         $phpbb_root_path = 'forums/';
  18.         $phpEx = substr(strrchr(__FILE__, '.'), 1);
  19.         include($phpbb_root_path . 'common.php');
  20.         include($phpbb_root_path . 'includes/functions_user.php');
  21.         include($phpbb_root_path . 'includes/ucp/ucp_register.php');
  22.         // Forum Database Variables
  23.         $host="yourhost.yourhostdomain.com"; // Host name
  24.         $dbusername="username"; // Mysql username
  25.         $dbpassword="databasepassword"; // Mysql password
  26.         $db_name="databasename"; // Database name
  27.         $users_tbl="phpbb_users"; // Table name for PHPBB Users
  28.         $group_tbl="phpbb_user_group"; // Table Name for PHPBB Groups
  29.         // Connect to server and select database
  30.         mysql_connect("$host", "$dbusername", "$dbpassword")or die("cannot connect");
  31.         mysql_select_db("$db_name")or die("cannot select DB");
  32.         // A check to see if the username is unique
  33.         $sql="SELECT * FROM $users_tbl WHERE username='$username'";
  34.         $result=mysql_query($sql);
  35.         $count=mysql_num_rows($result);
  36.     
  37.         // A check to see if the email is unique
  38.         $sql2="SELECT * FROM $users_tbl WHERE user_email='$user_email'";
  39.         $result2=mysql_query($sql2);
  40.         $count2=mysql_num_rows($result2);
  41.         if($count==1)
  42.         {
  43.             header("location: error.php");
  44.         }
  45.         elseif($count2==1)
  46.         {
  47.             header("location: error.php");
  48.         }
  49.         else
  50.         {
  51.     $sql_ary = array(
  52.       'username'     => $username,
  53.       'username_clean'  => $username_clean,
  54.       'user_password'   => phpbb_hash($password),
  55.       'user_pass_convert' => 0,
  56.       'user_email'    => $user_email,
  57.       'user_email_hash'  => crc32(strtolower($user_email)) . strlen($user_email),
  58.       'group_id'     => 2,
  59.       'user_type'     => 0,
  60.     );
  61.   user_add($sql_ary);
  62.         }
  63.     }
  64. }
Custom Web Design
  • natas
  • PHP Ninja
  • Proficient
  • No Avatar
  • Joined: Mar 28, 2009
  • Posts: 305
  • Loc: AFK
  • Status: Offline

Post March 14th, 2012, 9:17 pm

To allow users to login:

Code: [ Select ]
<form action="./phpBB3/ucp.php?mode=login" method="post">
    <label for="username">Username:</label>&nbsp;
    <input type="text" name="username" id="username" size="20" title="Username" />
    <label for="password">Password:</label>&nbsp;
    <input type="password" name="password" id="password" size="20" title="Password" />
    <input type="hidden" name="redirect" value="whereyouwanttheusertoendup.php" />
    <input type="submit" name="login" value="LOGIN" />
</form>
  1. <form action="./phpBB3/ucp.php?mode=login" method="post">
  2.     <label for="username">Username:</label>&nbsp;
  3.     <input type="text" name="username" id="username" size="20" title="Username" />
  4.     <label for="password">Password:</label>&nbsp;
  5.     <input type="password" name="password" id="password" size="20" title="Password" />
  6.     <input type="hidden" name="redirect" value="whereyouwanttheusertoendup.php" />
  7.     <input type="submit" name="login" value="LOGIN" />
  8. </form>
Custom Web Design
  • StonerLifestyle
  • Newbie
  • Newbie
  • No Avatar
  • Joined: Mar 14, 2012
  • Posts: 11
  • Status: Offline

Post March 14th, 2012, 9:39 pm

Thank you so much natas. I will work with the code you gave me and report back with results.

Take care
  • StonerLifestyle
  • Newbie
  • Newbie
  • No Avatar
  • Joined: Mar 14, 2012
  • Posts: 11
  • Status: Offline

Post March 14th, 2012, 10:12 pm

Hey Natas (or whoever wants to help), I pretty much did some copy/paste on the first code you posted on my home page. I saved my home page as a php file and just inserted the code right where I wanted it.

I of course changed the important info (host name, user for database, etc). But I am getting the following error on my page online now...


Warning: Cannot modify header information - headers already sent by (output started at /hermes/web06/b2402/moo.stonerlifestylecom/index.php:8) in /hermes/web06/b2402/moo.stonerlifestylecom/index.php on line 110

Now I did not edit the "run your own test here" part you had in the code. I am assuming I am getting this error because of this? I am talking about this code here:
Code: [ Select ]
if ($tests==false) // TOTALLY GENERIC, YOU WILL HAVE TO RUN YOUR OWN TESTS
  {
    header("location: error.php");
  }
  1. if ($tests==false) // TOTALLY GENERIC, YOU WILL HAVE TO RUN YOUR OWN TESTS
  2.   {
  3.     header("location: error.php");
  4.   }


Thanks for all replies.
  • natas
  • PHP Ninja
  • Proficient
  • No Avatar
  • Joined: Mar 28, 2009
  • Posts: 305
  • Loc: AFK
  • Status: Offline

Post March 14th, 2012, 10:18 pm

My code wasn't really meant to be copy/pasted. Looking back at it, I didn't even removed the opening brackets on line 1. lol.

Those headers are just redirects in case of an error, you can handle errors however you wish. The reason you are seeing "headers already sent" errors is because of some kind of output buffering deal. (I'll be honest. I don't really understand it).

I just add
ob_start();

to the top of my pages, and that seems to solve the problem.

You might want to check the PHP website to get more information.
Custom Web Design
  • StonerLifestyle
  • Newbie
  • Newbie
  • No Avatar
  • Joined: Mar 14, 2012
  • Posts: 11
  • Status: Offline

Post March 14th, 2012, 10:42 pm

I decided to run your second code, and that works wonderfully. I think registering from my home page is not a big deal to me, I will just link to register under the login.

I would really like to learn a way to display that the user is logged into the forums while on the home page. Would this be relatively simple to do? If so how would I go about it?

Basically I would like my home page to do the following:
1 - Check to see if the visitor on the home page is logged into the forums
2 - If yes, display this information on the home page
3 - If no, display that the visitor is not logged in the forums on the home page
4 - Provide a log in box and register link on the home page for the forums (Already have this done thanks to natas :D )
  • natas
  • PHP Ninja
  • Proficient
  • No Avatar
  • Joined: Mar 28, 2009
  • Posts: 305
  • Loc: AFK
  • Status: Offline

Post March 14th, 2012, 10:58 pm

Add this to the top of any page you wish to access PHPBB session information

Code: [ Select ]
  <?php
  define('IN_PHPBB', true);
  $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
  $phpEx = substr(strrchr(__FILE__, '.'), 1);
  include($phpbb_root_path . 'common.' . $phpEx);
  $user->session_begin();
  $auth->acl($user->data);
  $user->setup();
  ?>
  1.   <?php
  2.   define('IN_PHPBB', true);
  3.   $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
  4.   $phpEx = substr(strrchr(__FILE__, '.'), 1);
  5.   include($phpbb_root_path . 'common.' . $phpEx);
  6.   $user->session_begin();
  7.   $auth->acl($user->data);
  8.   $user->setup();
  9.   ?>


To check if a user is logged in:

Code: [ Select ]
<?php
if ($user->data['user_id'] == ANONYMOUS)
{
  echo "USER IS NOT LOGGED IN"; // or whatever else you want it to say
}

else
{
  echo "USER IS LOGGED IN"; // same here, edit the output as you wish
}

?>
  1. <?php
  2. if ($user->data['user_id'] == ANONYMOUS)
  3. {
  4.   echo "USER IS NOT LOGGED IN"; // or whatever else you want it to say
  5. }
  6. else
  7. {
  8.   echo "USER IS LOGGED IN"; // same here, edit the output as you wish
  9. }
  10. ?>
Custom Web Design
  • StonerLifestyle
  • Newbie
  • Newbie
  • No Avatar
  • Joined: Mar 14, 2012
  • Posts: 11
  • Status: Offline

Post March 15th, 2012, 12:59 am

Thank you so much Natas, I have been able to successfully run everything I want to run. The only thing I have left is how do I echo back the username of the site visitor if they are logged in?

I have the following code working here for this part but just don't know how I can echo back the user's name.

Code: [ Select ]
<?php
if ($user->data['user_id'] == ANONYMOUS) {
?>
  <form action="./forum/ucp.php?mode=login" method="post">
  <label for="username">Username:</label>
  &nbsp;
  <input type="text" name="username" id="username" size="20" title="Username" />
  <label for="password"><br>
  Password:</label>
  &nbsp;
  <input type="password" name="password" id="password" size="20" title="Password" />
  <input type="hidden" name="redirect" value="./index.php" />
  <br>
  <input type="submit" name="login" value="LOGIN" />
  </form>         

<?php }
else
{
 echo $user->data['user_name']; //This line does not work, I was just testing things
 echo "You are logged in."; // same here, edit the output as you wish
}
?>
  1. <?php
  2. if ($user->data['user_id'] == ANONYMOUS) {
  3. ?>
  4.   <form action="./forum/ucp.php?mode=login" method="post">
  5.   <label for="username">Username:</label>
  6.   &nbsp;
  7.   <input type="text" name="username" id="username" size="20" title="Username" />
  8.   <label for="password"><br>
  9.   Password:</label>
  10.   &nbsp;
  11.   <input type="password" name="password" id="password" size="20" title="Password" />
  12.   <input type="hidden" name="redirect" value="./index.php" />
  13.   <br>
  14.   <input type="submit" name="login" value="LOGIN" />
  15.   </form>         
  16. <?php }
  17. else
  18. {
  19.  echo $user->data['user_name']; //This line does not work, I was just testing things
  20.  echo "You are logged in."; // same here, edit the output as you wish
  21. }
  22. ?>
  • natas
  • PHP Ninja
  • Proficient
  • No Avatar
  • Joined: Mar 28, 2009
  • Posts: 305
  • Loc: AFK
  • Status: Offline

Post March 15th, 2012, 6:35 am

$user->data['username']
or
$user->data['username_clean']

I can't remember
Custom Web Design
  • StonerLifestyle
  • Newbie
  • Newbie
  • No Avatar
  • Joined: Mar 14, 2012
  • Posts: 11
  • Status: Offline

Post March 15th, 2012, 11:27 am

$user->data['username'] initially displayed some error at the top with warnings about some header info already being sent or something. But suddenly after a run through of tests to see if it functions properly (which it did) the errors were just all gone.

I have cycled through the pages more than a few times to test it all and there hasn't been an error since the first time I tried it. Weird but nice.

So I guess I got everything I need solved.

Have a wonderful day all, especially natas!
  • StonerLifestyle
  • Newbie
  • Newbie
  • No Avatar
  • Joined: Mar 14, 2012
  • Posts: 11
  • Status: Offline

Post March 16th, 2012, 10:55 am

Sorry one last thing guys...I am randomly seeing this error on my home page when you are not logged in yet. Once you log in, it goes away...

[phpBB Debug] PHP Warning: in file [ROOT]/includes/session.php on line 1035: Cannot modify header information - headers already sent by (output started at /hermes/web06/b2402/moo.stonerlifestylecom/index.php:8)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/session.php on line 1035: Cannot modify header information - headers already sent by (output started at /hermes/web06/b2402/moo.stonerlifestylecom/index.php:8)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/session.php on line 1035: Cannot modify header information - headers already sent by (output started at /hermes/web06/b2402/moo.stonerlifestylecom/index.php:8)

EDIT: I will note that the home page is still fully functional with the error messages just showing up on the top of the screen.
  • natas
  • PHP Ninja
  • Proficient
  • No Avatar
  • Joined: Mar 28, 2009
  • Posts: 305
  • Loc: AFK
  • Status: Offline

Post March 16th, 2012, 11:11 am

You could just turn error reporting off :)

Code: [ Select ]
error_reporting("E_ALL");

But that's kinda ignoring the problem.

Every time I get that header error, I just add this to the top of my page.

Code: [ Select ]
ob_start();


http://php.net/manual/en/function.ob-start.php
Custom Web Design
  • StonerLifestyle
  • Newbie
  • Newbie
  • No Avatar
  • Joined: Mar 14, 2012
  • Posts: 11
  • Status: Offline

Post March 16th, 2012, 12:19 pm

I inserted the ob_start(); line into various places on the home page and session.php file and could not get the error message to leave.

I also tried inserting the error message off thing as a test on the index and that did not make the error message leave either...

I must be placing the code in the wrong file/area of file?
  • natas
  • PHP Ninja
  • Proficient
  • No Avatar
  • Joined: Mar 28, 2009
  • Posts: 305
  • Loc: AFK
  • Status: Offline

Post March 16th, 2012, 1:13 pm

Did u place them inside PHP tags and on the top of your home page?
Custom Web Design
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post March 16th, 2012, 1:13 pm

Post Information

  • Total Posts in this topic: 20 posts
  • Users browsing this forum: Bigwebmaster and 219 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.