How to integrate website login with PHPBB3

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

34 Replies - 8790 Views - Last Post: 11 September 2013 - 11:17 AM Rate Topic: -----

#16 Logik22  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 166
  • Joined: 12-December 11

Re: How to integrate website login with PHPBB3

Posted 13 August 2013 - 03:19 PM

View Poste_i_pi, on 13 August 2013 - 03:05 PM, said:

Sorry, that initial HTML was a tad lacking, there was an unclosed quote and no submit button. Your html should look something like this:
<form method="post" action="/phpBB/ucp.php?mode=login">
    <label>Username</label>
    <input name="username" type="text" id="username" class="width120 textbox" tabindex="1" />
    <label>Password</label>
    <input name="password" type="password" id="password" class="width120 textbox" tabindex="2" />
    <input type="submit" value="Login" name="login">
</form>


So when you hit "Login" there, is that when it takes you to a blank page? If so, the path to ucp.php?mode=login may not be correct. You'll have to check the path to make sure it is directing to the correct file. What is the directory of your phpBB installation?



That's alright. I filled in the blanks. Thanks though!

The reason it redirected to the PHPBB3 login was because I didn't correctly implement your "users.php". I tried to implement it your way but the page loads blank. If I remove this code it's fine but doesn't have the login functionality

// Commence the phpBB3 user session
$user->session_begin();
$auth->acl($user->data);
$user->setup();
User::Initialise();


I figured that was because there was problems referencing the other PHP files so I tried a few different ways to "require" them.


This is my code:
Index.php
 <?php 

$phpbb_root_path = '/phpBB3/';
include $phpbb_root_path . 'common.php';
include $phpbb_root_path . 'includes/functions_user.' . $phpEx;

include $phpbb_root_path .'user.php';
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);

include('/phpBB3/common.php');
include('/phpBB3/includes/functions_display.'.$phpEx);
include('/phpBB3/user.php');

$phpbb_root_path = '/phpBB3/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
include($phpbb_root_path . 'user.' . $phpEx);

// Commence the phpBB3 user session
$user->session_begin();
$auth->acl($user->data);
$user->setup();
User::Initialise();




 // Connects to your Database 
$con = mysql_connect(##My login info here##);
if (!$con)
 {
 die('Could not connect: ' . mysql_error());
echo "Can't connect to DB";
 }
mysql_select_db("Stats", $con);


 //Checks if there is a login cookie

 if(isset($_COOKIE['ID_my_site']))


 //if there is, it logs you in and directes you to the members page

 { 
 	$username = $_COOKIE['ID_my_site']; 

 	$pass = $_COOKIE['Key_my_site'];

 	 	$check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error());

 	while($info = mysql_fetch_array( $check )) 	

 		{

 		if ($pass != $info['password']) 

 			{

 			 			}

 		else

 			{ 
			header("Location: members.php");


 			}

 		}

 }


 //if the login form is submitted 

 if (isset($_POST['submit'])) { // if form has been submitted



 // makes sure they filled it in

 	if(!$_POST['username'] | !$_POST['pass']) {

 		die("<html><head>
<link rel='stylesheet' type='text/css' href='style.css'>
</head></html> You did not fill in a required field.");

 	}

 	// checks it against the database



 	if (!get_magic_quotes_gpc()) {

 		$_POST['email'] = addslashes($_POST['email']);

 	}

 	$check = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'")or die(mysql_error());



 //Gives error if user dosen't exist

 $check2 = mysql_num_rows($check);

 if ($check2 == 0) {

 		die("<html><head>
<link rel='stylesheet' type='text/css' href='style.css'>
</head></html> That user does not exist in our database. <a href=add.php>Click Here to Register</a>'");

 				}

 while($info = mysql_fetch_array( $check )) 	

 {

 $_POST['pass'] = stripslashes($_POST['pass']);

 	$info['password'] = stripslashes($info['password']);
	


 //gives error if the password is wrong

 	if ($_POST['pass'] != $info['password']) {
	error_reporting(E_ALL);
	//header( 'Location: http://www.google.com' ); 
 		die("<html><head>
<link rel='stylesheet' type='text/css' href='style.css'>
</head></html>Incorrect password, please try again.");

 	}
	
	 else 

 { 

 // if login is ok then we add a cookie 

 	 $_POST['username'] = stripslashes($_POST['username']); 

 	 $hour = time() + 3600; 

 setcookie(ID_my_site, $_POST['username'], $hour); 

 setcookie(Key_my_site, $_POST['pass'], $hour);	 

 

 //then redirect them to the members area 
?>  
<html><meta http-equiv="refresh" content="0;url=home.html" />
<link href="style.css" rel="stylesheet" type="text/css" media="all" />
</html>  
 <?php 



 } 

 } 

 } 

 else 

{	 

 

 // if they are not logged in 

 ?><head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
  
<form method="post" action="phpBB3/ucp.php?mode=login">

<center>
 <p>&nbsp;</p>
 <p>&nbsp;</p>
 <p>&nbsp;</p>
 <p>&nbsp;</p>
 <p>&nbsp;</p>
 <p>&nbsp;</p>
 <p align="center">&nbsp;</p>
 <p>&nbsp;</p>
 <table border="0"> 

 <tr><td colspan=2><h1>Login</h1></td></tr> 

 <tr><td>Username:</td><td> 
   <input name="username" type="text" id="username" class="width120 textbox" tabindex="1" maxlength="40" />

 </td></tr> 

 <tr><td>Password:</td><td> 

 <input name="password" type="password" id="password" class="width120 textbox" tabindex="2" maxlength="50" />
 </form> 

 </td></tr> 

 <tr><td colspan="2" align="right"> 

 <input type="submit" name="submit" value="Login"> 

 </td></tr> 

 </table> 
</center>

 
 <div align="center"></div>
 <div align="center"></div>
 <?php 

 } 

 

 ?>


I created a user.php file with your code (only added PHP tags)

<?php
abstract class User
{
	/** @var mixed The phpBB user object. */
	public static $PhpbbUser;

	/**
	 * Returns the user's ID.
	 *
	 * @static
	 * @return int The user's ID.
	 */
	public static function ID()
	{
		return (int)self::$PhpbbUser->data['user_id'];
	}

	/**
	 * Initialises the static user object.
	 *
	 * @static
	 */
	public static function Initialise()
	{
		// Load the user
        if(!isset(self::$PhpbbUser))
        {
            global $user;
            self::$PhpbbUser = $user;
        }
	}

	/**
	 * Checks whether the user is anonymous.
	 *
	 * @static
	 * @return bool
	 */
	public static function IsAnon()
	{
		// Is the user Anonymous in phpBB?
		return self::$PhpbbUser->data['user_id'] == ANONYMOUS;
	}

	/**
	 * Checks whether the user is a bot.
	 *
	 * @static
	 * @return mixed
	 */
    public static function IsBot()
    {
        // Is the user a Bot in phpBB?
        return self::$PhpbbUser->data['is_bot'];
    }

	/**
	 * Checks whether the user is registered.
	 *
	 * @static
	 * @return bool
	 */
    public static function IsRegistered()
    {
        // Is the user registered in phpBB?
        return self::$PhpbbUser->data['user_id'] != ANONYMOUS;
    }

}
?>

This post has been edited by Logik22: 13 August 2013 - 03:21 PM

Was This Post Helpful? 0
  • +
  • -

#17 e_i_pi  Icon User is offline

  • = -1
  • member icon

Reputation: 801
  • View blog
  • Posts: 1,689
  • Joined: 30-January 09

Re: How to integrate website login with PHPBB3

Posted 13 August 2013 - 04:20 PM

Doh, sorry when I put that config stuff together I was snipping it out of my config file, while is 200 lines long and has a mix of phpBB and my application. You might be missing a flag telling phpBB that you're "in" phpBB, or you may be missing references to phpBB user functions. The code I use to test if the user functions are loaded is a bit messy, but it works. Let's try this as your config:
if(!defined('IN_PHPBB'))
{
	define('IN_PHPBB', TRUE);
}
$phpbb_root_path = /* enter your phpBB root path here */;
include $phpbb_root_path . 'common.php';
include $phpbb_root_path . 'includes/functions_user.' . $phpEx;
include /* enter the path to the User class file here */;

// Commence the phpBB3 user session
$user->session_begin();
$auth->acl($user->data);
$user->setup();

// Instantiate the common functions of phpBB3
if (!function_exists("group_memberships"))
{
	include $phpbb_root_path . 'includes/functions_user.' . $phpEx;
}

// Initialise your User singleton
User::Initialise();



If you're still getting a blank page, then prepend this code, which will spit out any errors you're encountering:
ini_set('error_reporting', E_ALL | E_STRICT);
error_reporting(E_ALL | E_STRICT);



That will help us identify where it's falling down
Was This Post Helpful? 0
  • +
  • -

#18 Logik22  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 166
  • Joined: 12-December 11

Re: How to integrate website login with PHPBB3

Posted 13 August 2013 - 04:33 PM

I've added this to my login page (index.php):

 <?php 
ini_set('error_reporting', E_ALL | E_STRICT);
error_reporting(E_ALL | E_STRICT);


if(!defined('IN_PHPBB'))
{
	define('IN_PHPBB', TRUE);
}
$phpbb_root_path = '/phpBB3/';
include $phpbb_root_path . 'common.php';
include $phpbb_root_path . 'includes/functions_user.' . $phpEx;
include '/phpBB3/user.php';

// Commence the phpBB3 user session
$user->session_begin();
$auth->acl($user->data);
$user->setup();

// Instantiate the common functions of phpBB3
if (!function_exists("group_memberships"))
{
	include $phpbb_root_path . 'includes/functions_user.' . $phpEx;
}

// Initialise your User singleton
User::Initialise();




 // Connects to your Database 
$con = mysql_connect(##Database connection###);
if (!$con)
 {
 die('Could not connect: ' . mysql_error());
echo "Can't connect to DB";
 }
mysql_select_db("Stats", $con);


 //Checks if there is a login cookie

 if(isset($_COOKIE['ID_my_site']))


 //if there is, it logs you in and directes you to the members page

 { 
 	$username = $_COOKIE['ID_my_site']; 

 	$pass = $_COOKIE['Key_my_site'];

 	 	$check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error());

 	while($info = mysql_fetch_array( $check )) 	

 		{

 		if ($pass != $info['password']) 

 			{

 			 			}

 		else

 			{ 
			header("Location: members.php");


 			}

 		}

 }


 //if the login form is submitted 

 if (isset($_POST['submit'])) { // if form has been submitted



 // makes sure they filled it in

 	if(!$_POST['username'] | !$_POST['pass']) {

 		die("<html><head>
<link rel='stylesheet' type='text/css' href='style.css'>
</head></html> You did not fill in a required field.");

 	}

 	// checks it against the database



 	if (!get_magic_quotes_gpc()) {

 		$_POST['email'] = addslashes($_POST['email']);

 	}

 	$check = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'")or die(mysql_error());



 //Gives error if user dosen't exist

 $check2 = mysql_num_rows($check);

 if ($check2 == 0) {

 		die("<html><head>
<link rel='stylesheet' type='text/css' href='style.css'>
</head></html> That user does not exist in our database. <a href=add.php>Click Here to Register</a>'");

 				}

 while($info = mysql_fetch_array( $check )) 	

 {

 $_POST['pass'] = stripslashes($_POST['pass']);

 	$info['password'] = stripslashes($info['password']);
	


 //gives error if the password is wrong

 	if ($_POST['pass'] != $info['password']) {
	error_reporting(E_ALL);
	//header( 'Location: http://www.google.com' ); 
 		die("<html><head>
<link rel='stylesheet' type='text/css' href='style.css'>
</head></html>Incorrect password, please try again.");

 	}
	
	 else 

 { 

 // if login is ok then we add a cookie 

 	 $_POST['username'] = stripslashes($_POST['username']); 

 	 $hour = time() + 3600; 

 setcookie(ID_my_site, $_POST['username'], $hour); 

 setcookie(Key_my_site, $_POST['pass'], $hour);	 

 

 //then redirect them to the members area 
?>  
<html><meta http-equiv="refresh" content="0;url=home.html" />
<link href="style.css" rel="stylesheet" type="text/css" media="all" />
</html>  
 <?php 



 } 

 } 

 } 

 else 

{	 

 

 // if they are not logged in 

 ?><head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
  
<form method="post" action="phpBB3/ucp.php?mode=login">

<center>
 <p>&nbsp;</p>
 <p>&nbsp;</p>
 <p>&nbsp;</p>
 <p>&nbsp;</p>
 <p>&nbsp;</p>
 <p>&nbsp;</p>
 <p align="center">&nbsp;</p>
 <p>&nbsp;</p>
 <table border="0"> 

 <tr><td colspan=2><h1>Login</h1></td></tr> 

 <tr><td>Username:</td><td> 
   <input name="username" type="text" id="username" class="width120 textbox" tabindex="1" maxlength="40" />

 </td></tr> 

 <tr><td>Password:</td><td> 

 <input name="password" type="password" id="password" class="width120 textbox" tabindex="2" maxlength="50" />
 </form> 

 </td></tr> 

 <tr><td colspan="2" align="right"> 

 <input type="submit" name="submit" value="Login"> 

 </td></tr> 

 </table> 
</center>

 
 <div align="center"></div>
 <div align="center"></div>
 <?php 
 } 
  ?>


What do you mean by "prepend" the error output code? I tried to put it at the beginning and end but I don't get any different response. It still gives me a blank page when index.php loads.

When I remove this code it works.

// Commence the phpBB3 user session
$user->session_begin();
$auth->acl($user->data);
$user->setup();

Was This Post Helpful? 0
  • +
  • -

#19 e_i_pi  Icon User is offline

  • = -1
  • member icon

Reputation: 801
  • View blog
  • Posts: 1,689
  • Joined: 30-January 09

Re: How to integrate website login with PHPBB3

Posted 13 August 2013 - 04:38 PM

By "prepend" I mean place the code at the top, like you have. You might also need this directive to display the errors:
ini_set('display_errors', true);



What happens when you include these lines one at a time?
$user->session_begin();
$auth->acl($user->data);
$user->setup();


That will track down which method it is failing on
Was This Post Helpful? 0
  • +
  • -

#20 Logik22  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 166
  • Joined: 12-December 11

Re: How to integrate website login with PHPBB3

Posted 13 August 2013 - 04:45 PM

View Poste_i_pi, on 13 August 2013 - 04:38 PM, said:

By "prepend" I mean place the code at the top, like you have. You might also need this directive to display the errors:
ini_set('display_errors', true);



What happens when you include these lines one at a time?
$user->session_begin();
$auth->acl($user->data);
$user->setup();


That will track down which method it is failing on



Ahh yes, I added the "display_errors" code at the top and it displayed several errors:
Warning: include(/phpBB3/common.php) [function.include]: failed to open stream: No such file or directory in /share/MD0_DATA/Web/index.php on line 12

Warning: include() [function.include]: Failed opening '/phpBB3/common.php' for inclusion (include_path='.:/etc/config/php') in /share/MD0_DATA/Web/index.php on line 12

Notice: Undefined variable: phpEx in /share/MD0_DATA/Web/index.php on line 13

Warning: include(/phpBB3/includes/functions_user.) [function.include]: failed to open stream: No such file or directory in /share/MD0_DATA/Web/index.php on line 13

Warning: include() [function.include]: Failed opening '/phpBB3/includes/functions_user.' for inclusion (include_path='.:/etc/config/php') in /share/MD0_DATA/Web/index.php on line 13

Warning: include(/phpBB3/user.php) [function.include]: failed to open stream: No such file or directory in /share/MD0_DATA/Web/index.php on line 14

Warning: include() [function.include]: Failed opening '/phpBB3/user.php' for inclusion (include_path='.:/etc/config/php') in /share/MD0_DATA/Web/index.php on line 14

Notice: Undefined variable: user in /share/MD0_DATA/Web/index.php on line 17

Fatal error: Call to a member function session_begin() on a non-object in /share/MD0_DATA/Web/index.php on line 17


As far as my file directory I have Index.php on the same level as my phpBB3 folder.

Now when I comment out:

// Commence the phpBB3 user session
$user->session_begin();
$auth->acl($user->data);
$user->setup();




It creates more errors

Notice: Undefined variable: phpbb_root_path in /share/MD0_DATA/Web/index.php on line 12

Warning: include(common.php) [function.include]: failed to open stream: No such file or directory in /share/MD0_DATA/Web/index.php on line 12

Warning: include() [function.include]: Failed opening 'common.php' for inclusion (include_path='.:/etc/config/php') in /share/MD0_DATA/Web/index.php on line 12

Notice: Undefined variable: phpbb_root_path in /share/MD0_DATA/Web/index.php on line 13

Notice: Undefined variable: phpEx in /share/MD0_DATA/Web/index.php on line 13

Warning: include(includes/functions_user.) [function.include]: failed to open stream: No such file or directory in /share/MD0_DATA/Web/index.php on line 13

Warning: include() [function.include]: Failed opening 'includes/functions_user.' for inclusion (include_path='.:/etc/config/php') in /share/MD0_DATA/Web/index.php on line 13

Warning: include(/phpBB3/user.php) [function.include]: failed to open stream: No such file or directory in /share/MD0_DATA/Web/index.php on line 14

Warning: include() [function.include]: Failed opening '/phpBB3/user.php' for inclusion (include_path='.:/etc/config/php') in /share/MD0_DATA/Web/index.php on line 14

Notice: Undefined variable: phpbb_root_path in /share/MD0_DATA/Web/index.php on line 24

Notice: Undefined variable: phpEx in /share/MD0_DATA/Web/index.php on line 24

Warning: include(includes/functions_user.) [function.include]: failed to open stream: No such file or directory in /share/MD0_DATA/Web/index.php on line 24

Warning: include() [function.include]: Failed opening 'includes/functions_user.' for inclusion (include_path='.:/etc/config/php') in /share/MD0_DATA/Web/index.php on line 24

Fatal error: Class 'User' not found in /share/MD0_DATA/Web/index.php on line 28



If I comment out the "require" code I get:
Notice: Undefined variable: user in /share/MD0_DATA/Web/index.php on line 17

Fatal error: Call to a member function session_begin() on a non-object in /share/MD0_DATA/Web/index.php on line 17

Was This Post Helpful? 0
  • +
  • -

#21 e_i_pi  Icon User is offline

  • = -1
  • member icon

Reputation: 801
  • View blog
  • Posts: 1,689
  • Joined: 30-January 09

Re: How to integrate website login with PHPBB3

Posted 13 August 2013 - 04:52 PM

Alright, so that's telling you your variable $phpbb_root_path is incorrectly defined. You'll have to play around with some options here. Firstly, I'd assign it the value './phpBB3/', though I doubt that will help. Next I'd try '/share/MD0_DATA/Web/phpBB3', which seems to be the correct path. Pathing in applications can be an issue, and is probably best left for a different topic, but you essentially need to determine the correct path so that PHP can find the files you're trying to include.
Was This Post Helpful? 0
  • +
  • -

#22 Logik22  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 166
  • Joined: 12-December 11

Re: How to integrate website login with PHPBB3

Posted 13 August 2013 - 05:05 PM

View Poste_i_pi, on 13 August 2013 - 04:52 PM, said:

Alright, so that's telling you your variable $phpbb_root_path is incorrectly defined. You'll have to play around with some options here. Firstly, I'd assign it the value './phpBB3/', though I doubt that will help. Next I'd try '/share/MD0_DATA/Web/phpBB3', which seems to be the correct path. Pathing in applications can be an issue, and is probably best left for a different topic, but you essentially need to determine the correct path so that PHP can find the files you're trying to include.


I think I sort of understand the problem. Is it that the path that it's at (through Windows Explorer) isn't necessarily the path the PHP file will take to find it?

I've tried adding in "'/share/MD0_DATA/Web/phpBB3'" as well as a few variations of paths but I still can't get it to work. What topic do you suggest I research to try to find my answer?

FYI, this server is hosted on my QNAP. It's attached to my home network (same subnet as my PC). I'm not sure if that would affect this as opposed to it being hosted through an actual hosting company.

Thanks for all of your help!

Edit:

When I added "." in front of my path my errors are reduced to...

Notice: Undefined variable: phpEx in /share/MD0_DATA/Web/phpBB3/common.php on line 19

Warning: require(./phpBB3/includes/startup.) [function.require]: failed to open stream: No such file or directory in /share/MD0_DATA/Web/phpBB3/common.php on line 19

Fatal error: require() [function.require]: Failed opening required './phpBB3/includes/startup.' (include_path='.:/etc/config/php') in /share/MD0_DATA/Web/phpBB3/common.php on line 19

This post has been edited by Logik22: 13 August 2013 - 05:11 PM

Was This Post Helpful? 0
  • +
  • -

#23 e_i_pi  Icon User is offline

  • = -1
  • member icon

Reputation: 801
  • View blog
  • Posts: 1,689
  • Joined: 30-January 09

Re: How to integrate website login with PHPBB3

Posted 13 August 2013 - 05:21 PM

Alright, go with the ".", and change any reference to $phpEx to the string "php". e.g., the code:
include $phpbb_root_path . 'includes/functions_user.' . $phpEx;


should change to
include $phpbb_root_path . 'includes/functions_user.php';




EDIT: That looks like it might be an issue in phpBB itself. Cover your bases by adding the following line of code:
$phpEx = 'php';


This post has been edited by e_i_pi: 13 August 2013 - 05:26 PM

Was This Post Helpful? 0
  • +
  • -

#24 Logik22  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 166
  • Joined: 12-December 11

Re: How to integrate website login with PHPBB3

Posted 13 August 2013 - 05:27 PM

View Poste_i_pi, on 13 August 2013 - 05:21 PM, said:

Alright, go with the ".", and change any reference to $phpEx to the string "php". e.g., the code:
include $phpbb_root_path . 'includes/functions_user.' . $phpEx;


should change to
include $phpbb_root_path . 'includes/functions_user.php';




I removed ". $phpEx" and added php to the file path and I get:

Warning: include(./phpBB3/includes/start.php) [function.include]: failed to open stream: No such file or directory in /share/MD0_DATA/Web/index.php on line 12

Warning: include() [function.include]: Failed opening './phpBB3/includes/start.php' for inclusion (include_path='.:/etc/config/php') in /share/MD0_DATA/Web/index.php on line 12

Notice: Undefined variable: phpEx in /share/MD0_DATA/Web/phpBB3/common.php on line 19

Warning: require(./phpBB3/includes/startup.) [function.require]: failed to open stream: No such file or directory in /share/MD0_DATA/Web/phpBB3/common.php on line 19

Fatal error: require() [function.require]: Failed opening required './phpBB3/includes/startup.' (include_path='.:/etc/config/php') in /share/MD0_DATA/Web/phpBB3/common.php on line 19



Why are the errors referencing these files?:
(./phpBB3/includes/start.php)
(./phpBB3/includes/startup.)

Also, could it be a permissions issue? Since this is located on a NAS how do I know what credentials it's using to try to access the PHPBB3 files stored on the NAS?

This post has been edited by Logik22: 13 August 2013 - 05:33 PM

Was This Post Helpful? 0
  • +
  • -

#25 e_i_pi  Icon User is offline

  • = -1
  • member icon

Reputation: 801
  • View blog
  • Posts: 1,689
  • Joined: 30-January 09

Re: How to integrate website login with PHPBB3

Posted 13 August 2013 - 05:35 PM

Yep, sorry again, add the line
$phpEx = 'php';


...before you start including phpBB files. That variable gets defined in phpBB, but only if you go through a phpBB page. If you're bootstrapping from your application, you need to define it yourself.
Was This Post Helpful? 0
  • +
  • -

#26 Logik22  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 166
  • Joined: 12-December 11

Re: How to integrate website login with PHPBB3

Posted 13 August 2013 - 05:43 PM

View Poste_i_pi, on 13 August 2013 - 05:35 PM, said:

Yep, sorry again, add the line
$phpEx = 'php';


...before you start including phpBB files. That variable gets defined in phpBB, but only if you go through a phpBB page. If you're bootstrapping from your application, you need to define it yourself.


No Problem. I'm learning a lot! Thanks!

This is where I'm at:

Errors:
Warning: include(./phpBB3/includes/start.php) [function.include]: failed to open stream: No such file or directory in /share/MD0_DATA/Web/index.php on line 13

Warning: include() [function.include]: Failed opening './phpBB3/includes/start.php' for inclusion (include_path='.:/etc/config/php') in /share/MD0_DATA/Web/index.php on line 13

Fatal error: Cannot redeclare class user in /share/MD0_DATA/Web/phpBB3/user.php on line 2



index.php
 <?php 
 $phpEx = 'php';
ini_set('display_errors', true);
ini_set('error_reporting', E_ALL | E_STRICT);
error_reporting(E_ALL | E_STRICT);


if(!defined('IN_PHPBB'))
{
	define('IN_PHPBB', TRUE);
}
$phpbb_root_path = './phpBB3/';
include './phpBB3/includes/start.php';
include $phpbb_root_path . 'common.php';
include $phpbb_root_path . 'includes/functions_user.'. $phpEx;
include './phpBB3/user.php';

// Commence the phpBB3 user session
$user->session_begin();
$auth->acl($user->data);
$user->setup();

// Instantiate the common functions of phpBB3
if (!function_exists("group_memberships"))
{
	include $phpbb_root_path . 'includes/functions_user.'. $phpEx;
}

// Initialise your User singleton
User::Initialise();




 // Connects to your Database 
$con = mysql_connect(##database connection##);
if (!$con)
 {
 die('Could not connect: ' . mysql_error());
echo "Can't connect to DB";
 }
mysql_select_db("Stats", $con);


 //Checks if there is a login cookie

 if(isset($_COOKIE['ID_my_site']))


 //if there is, it logs you in and directes you to the members page

 { 
 	$username = $_COOKIE['ID_my_site']; 

 	$pass = $_COOKIE['Key_my_site'];

 	 	$check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error());

 	while($info = mysql_fetch_array( $check )) 	

 		{

 		if ($pass != $info['password']) 

 			{

 			 			}

 		else

 			{ 
			header("Location: members.php");


 			}

 		}

 }


 //if the login form is submitted 

 if (isset($_POST['submit'])) { // if form has been submitted



 // makes sure they filled it in

 	if(!$_POST['username'] | !$_POST['pass']) {

 		die("<html><head>
<link rel='stylesheet' type='text/css' href='style.css'>
</head></html> You did not fill in a required field.");

 	}

 	// checks it against the database



 	if (!get_magic_quotes_gpc()) {

 		$_POST['email'] = addslashes($_POST['email']);

 	}

 	$check = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'")or die(mysql_error());



 //Gives error if user dosen't exist

 $check2 = mysql_num_rows($check);

 if ($check2 == 0) {

 		die("<html><head>
<link rel='stylesheet' type='text/css' href='style.css'>
</head></html> That user does not exist in our database. <a href=add.php>Click Here to Register</a>'");

 				}

 while($info = mysql_fetch_array( $check )) 	

 {

 $_POST['pass'] = stripslashes($_POST['pass']);

 	$info['password'] = stripslashes($info['password']);
	


 //gives error if the password is wrong

 	if ($_POST['pass'] != $info['password']) {
	error_reporting(E_ALL);
	//header( 'Location: http://www.google.com' ); 
 		die("<html><head>
<link rel='stylesheet' type='text/css' href='style.css'>
</head></html>Incorrect password, please try again.");

 	}
	
	 else 

 { 

 // if login is ok then we add a cookie 

 	 $_POST['username'] = stripslashes($_POST['username']); 

 	 $hour = time() + 3600; 

 setcookie(ID_my_site, $_POST['username'], $hour); 

 setcookie(Key_my_site, $_POST['pass'], $hour);	 

 

 //then redirect them to the members area 
?>  
<html><meta http-equiv="refresh" content="0;url=home.html" />
<link href="style.css" rel="stylesheet" type="text/css" media="all" />
</html>  
 <?php 



 } 

 } 

 } 

 else 

{	 

 

 // if they are not logged in 

 ?><head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
  
<form method="post" action="phpBB3/ucp.php?mode=login">

<center>
 <p>&nbsp;</p>
 <p>&nbsp;</p>
 <p>&nbsp;</p>
 <p>&nbsp;</p>
 <p>&nbsp;</p>
 <p>&nbsp;</p>
 <p align="center">&nbsp;</p>
 <p>&nbsp;</p>
 <table border="0"> 

 <tr><td colspan=2><h1>Login</h1></td></tr> 

 <tr><td>Username:</td><td> 
   <input name="username" type="text" id="username" class="width120 textbox" tabindex="1" maxlength="40" />

 </td></tr> 

 <tr><td>Password:</td><td> 

 <input name="password" type="password" id="password" class="width120 textbox" tabindex="2" maxlength="50" />
 </form> 

 </td></tr> 

 <tr><td colspan="2" align="right"> 

 <input type="submit" name="submit" value="Login"> 

 </td></tr> 

 </table> 
</center>

 
 <div align="center"></div>
 <div align="center"></div>
 <?php 
 } 
  ?>


user.php
<?php
abstract class User
{
	/** @var mixed The phpBB user object. */
	public static $PhpbbUser;

	/**
	 * Returns the user's ID.
	 *
	 * @static
	 * @return int The user's ID.
	 */
	public static function ID()
	{
		return (int)self::$PhpbbUser->data['user_id'];
	}

	/**
	 * Initialises the static user object.
	 *
	 * @static
	 */
	public static function Initialise()
	{
		// Load the user
        if(!isset(self::$PhpbbUser))
        {
            global $user;
            self::$PhpbbUser = $user;
        }
	}

	/**
	 * Checks whether the user is anonymous.
	 *
	 * @static
	 * @return bool
	 */
	public static function IsAnon()
	{
		// Is the user Anonymous in phpBB?
		return self::$PhpbbUser->data['user_id'] == ANONYMOUS;
	}

	/**
	 * Checks whether the user is a bot.
	 *
	 * @static
	 * @return mixed
	 */
    public static function IsBot()
    {
        // Is the user a Bot in phpBB?
        return self::$PhpbbUser->data['is_bot'];
    }

	/**
	 * Checks whether the user is registered.
	 *
	 * @static
	 * @return bool
	 */
    public static function IsRegistered()
    {
        // Is the user registered in phpBB?
        return self::$PhpbbUser->data['user_id'] != ANONYMOUS;
    }

}
?>



Edit: should /includes/start actually be /includes/startup? If so, the only error I get is:
Fatal error: Cannot redeclare class user in /share/MD0_DATA/Web/phpBB3/user.php on line 2

This post has been edited by Logik22: 13 August 2013 - 05:46 PM

Was This Post Helpful? 0
  • +
  • -

#27 Logik22  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 166
  • Joined: 12-December 11

Re: How to integrate website login with PHPBB3

Posted 13 August 2013 - 05:52 PM

In my QNAP NAS I enabled "WebDav"
http://www.qnap.com/...lang=en&sn=2705
WebDAV (Web-based Distributed Authoring and Versioning), is a set of extensions to the HTTP(S) protocol that allows a web server to appear as a standard network drive. With WebDAV support, the QNAP NAS user will be able to access the share folders via HTTP/HTTPS protocol remotely.


and now my only error is:
Fatal error: Cannot redeclare deregister_globals() in /share/MD0_DATA/Web/phpBB3/includes/startup.php on line 44



Edit: I disabled WebDav and I'm back with the other error:

Fatal error: Cannot redeclare class user in /share/MD0_DATA/Web/phpBB3/user.php on line 2



In "user.php" I changed the user class to "user2" and in index.php I also updated the new name to "User2::Initialise();"

Current errors are:

[phpBB Debug] PHP Warning: in file [ROOT]/includes/session.php on line 1042: Cannot modify header information - headers already sent by (output started at /share/MD0_DATA/Web/index.php:1)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/session.php on line 1042: Cannot modify header information - headers already sent by (output started at /share/MD0_DATA/Web/index.php:1)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/session.php on line 1042: Cannot modify header information - headers already sent by (output started at /share/MD0_DATA/Web/index.php:1)


It looks like this happens when information is being sent to the user before the header. Not terribly sure what that means but I'm going to look in to it.

This post has been edited by Logik22: 13 August 2013 - 06:00 PM

Was This Post Helpful? 0
  • +
  • -

#28 Logik22  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 166
  • Joined: 12-December 11

Re: How to integrate website login with PHPBB3

Posted 13 August 2013 - 06:14 PM

I think we got it working! I had my login button with a name as "submit" instead of "login". I need to tweak this a little bit so it redirects to "home.html" instead of the phpBB3 forums but I think I saw that code earlier. It should just be a matter of finding the redirect code and changing it. I'll probably also have to better understand Sessions().

Thanks for all of the help!

File structure:
Index.php
/phpBB3/

Index.php
<?php 
 $phpEx = 'php';
ini_set('display_errors', true);
ini_set('error_reporting', E_ALL | E_STRICT);
error_reporting(E_ALL | E_STRICT);


if(!defined('IN_PHPBB'))
{
	define('IN_PHPBB', TRUE);
}
$phpbb_root_path = './phpBB3/';
include './phpBB3/includes/startup.php';
include $phpbb_root_path . 'common.php';
include $phpbb_root_path . 'includes/functions_user.'. $phpEx;
include './phpBB3/user.php';

// Commence the phpBB3 user session
$user->session_begin();
$auth->acl($user->data);
$user->setup();

// Instantiate the common functions of phpBB3
if (!function_exists("group_memberships"))
{
	include $phpbb_root_path . 'includes/functions_user.'. $phpEx;
}

// Initialise your User singleton
User2::Initialise();




 // Connects to your Database 
$con = mysql_connect(##Your Database + credentials go here###);
if (!$con)
 {
 die('Could not connect: ' . mysql_error());
echo "Can't connect to DB";
 }
mysql_select_db("Stats", $con);


 //Checks if there is a login cookie

 if(isset($_COOKIE['ID_my_site']))


 //if there is, it logs you in and directes you to the members page

 { 
 	$username = $_COOKIE['ID_my_site']; 

 	$pass = $_COOKIE['Key_my_site'];

 	 	$check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error());

 	while($info = mysql_fetch_array( $check )) 	

 		{

 		if ($pass != $info['password']) 

 			{

 			 			}

 		else

 			{ 
			header("Location: members.php");


 			}

 		}

 }


 //if the login form is submitted 

 if (isset($_POST['submit'])) { // if form has been submitted



 // makes sure they filled it in

 	if(!$_POST['username'] | !$_POST['pass']) {

 		die("<html><head>
<link rel='stylesheet' type='text/css' href='style.css'>
</head></html> You did not fill in a required field.");

 	}

 	// checks it against the database



 	if (!get_magic_quotes_gpc()) {

 		$_POST['email'] = addslashes($_POST['email']);

 	}

 	$check = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'")or die(mysql_error());



 //Gives error if user dosen't exist

 $check2 = mysql_num_rows($check);

 if ($check2 == 0) {

 		die("<html><head>
<link rel='stylesheet' type='text/css' href='style.css'>
</head></html> That user does not exist in our database. <a href=add.php>Click Here to Register</a>'");

 				}

 while($info = mysql_fetch_array( $check )) 	

 {

 $_POST['pass'] = stripslashes($_POST['pass']);

 	$info['password'] = stripslashes($info['password']);
	


 //gives error if the password is wrong

 	if ($_POST['pass'] != $info['password']) {
	error_reporting(E_ALL);
	//header( 'Location: http://www.google.com' ); 
 		die("<html><head>
<link rel='stylesheet' type='text/css' href='style.css'>
</head></html>Incorrect password, please try again.");

 	}
	
	 else 

 { 

 // if login is ok then we add a cookie 

 	 $_POST['username'] = stripslashes($_POST['username']); 

 	 $hour = time() + 3600; 

 setcookie(ID_my_site, $_POST['username'], $hour); 

 setcookie(Key_my_site, $_POST['pass'], $hour);	 

 

 //then redirect them to the members area 
?>  
<html><meta http-equiv="refresh" content="0;url=home.html" />
<link href="style.css" rel="stylesheet" type="text/css" media="all" />
</html>  
<?php 



 } 

 } 

 } 

 else 

{	 

 

 // if they are not logged in 

?>
 <head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
  
<form method="post" action="./phpBB3/ucp.php?mode=login">

<center>
 <p>&nbsp;</p>
 <p>&nbsp;</p>
 <p>&nbsp;</p>
 <p>&nbsp;</p>
 <p>&nbsp;</p>
 <p>&nbsp;</p>
 <p align="center">&nbsp;</p>
 <p>&nbsp;</p>
 <table border="0"> 

 <tr><td colspan=2><h1>Login</h1></td></tr> 

 <tr><td>Username:</td><td> 
   <input name="username" type="text" id="username" class="width120 textbox" tabindex="1" maxlength="40" />

 </td></tr> 

 <tr><td>Password:</td><td> 

 <input name="password" type="password" id="password" class="width120 textbox" tabindex="2" maxlength="50" />

    </td>
    </tr> 
     <tr><td colspan="2" align="right"> 

     <input type="submit" name="login" value="Login"> 

 <input type="hidden" name="redirect" value="../home.html" />

 </td></tr> 
 </form> 




 </table> 
</center>

 
 <div align="center"></div>
 <div align="center"></div>
<?php 
 } 
?>


newly created user.php file placed in the root of /phpBB3/:
<?php
abstract class User2
{
	/** @var mixed The phpBB user object. */
	public static $PhpbbUser;

	/**
	 * Returns the user's ID.
	 *
	 * @static
	 * @return int The user's ID.
	 */
	public static function ID()
	{
		return (int)self::$PhpbbUser->data['user_id'];
	}

	/**
	 * Initialises the static user object.
	 *
	 * @static
	 */
	public static function Initialise()
	{
		// Load the user
        if(!isset(self::$PhpbbUser))
        {
            global $user;
            self::$PhpbbUser = $user;
        }
	}

	/**
	 * Checks whether the user is anonymous.
	 *
	 * @static
	 * @return bool
	 */
	public static function IsAnon()
	{
		// Is the user Anonymous in phpBB?
		return self::$PhpbbUser->data['user_id'] == ANONYMOUS;
	}

	/**
	 * Checks whether the user is a bot.
	 *
	 * @static
	 * @return mixed
	 */
    public static function IsBot()
    {
        // Is the user a Bot in phpBB?
        return self::$PhpbbUser->data['is_bot'];
    }

	/**
	 * Checks whether the user is registered.
	 *
	 * @static
	 * @return bool
	 */
    public static function IsRegistered()
    {
        // Is the user registered in phpBB?
        return self::$PhpbbUser->data['user_id'] != ANONYMOUS;
    }

}
?>

This post has been edited by Logik22: 14 August 2013 - 07:02 AM

Was This Post Helpful? 0
  • +
  • -

#29 e_i_pi  Icon User is offline

  • = -1
  • member icon

Reputation: 801
  • View blog
  • Posts: 1,689
  • Joined: 30-January 09

Re: How to integrate website login with PHPBB3

Posted 13 August 2013 - 06:16 PM

Enable WebDAV, then change the first part of your index.php to this:
 <?php 
 $phpEx = 'php';
ini_set('display_errors', true);
ini_set('error_reporting', E_ALL | E_STRICT);
error_reporting(E_ALL | E_STRICT);


if(!defined('IN_PHPBB'))
{
	define('IN_PHPBB', TRUE);
}
$phpbb_root_path = './phpBB3/';
include $phpbb_root_path . 'common.php';
include $phpbb_root_path . 'includes/functions_user.'. $phpEx;
include './phpBB3/user.php';

// Commence the phpBB3 user session
$user->session_begin();
$auth->acl($user->data);
$user->setup();

// Initialise your User singleton
User::Initialise();


That should do the trick
Was This Post Helpful? 0
  • +
  • -

#30 Logik22  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 166
  • Joined: 12-December 11

Re: How to integrate website login with PHPBB3

Posted 06 September 2013 - 12:41 PM

View Poste_i_pi, on 13 August 2013 - 06:16 PM, said:

Enable WebDAV, then change the first part of your index.php to this:
 <?php 
 $phpEx = 'php';
ini_set('display_errors', true);
ini_set('error_reporting', E_ALL | E_STRICT);
error_reporting(E_ALL | E_STRICT);


if(!defined('IN_PHPBB'))
{
	define('IN_PHPBB', TRUE);
}
$phpbb_root_path = './phpBB3/';
include $phpbb_root_path . 'common.php';
include $phpbb_root_path . 'includes/functions_user.'. $phpEx;
include './phpBB3/user.php';

// Commence the phpBB3 user session
$user->session_begin();
$auth->acl($user->data);
$user->setup();

// Initialise your User singleton
User::Initialise();


That should do the trick



We might to change this a little bit. I had trouble using "User::Intitialise();".

I'm using the code below but I haven't tested it completely. I just know it forwards you to another page if you're not logged in. I don't have the login/session on all my pages though.

Top of my Index code:

<?php
//Display Errors
ini_set('error_reporting', E_ALL | E_STRICT);
error_reporting(E_ALL | E_STRICT);

define('IN_PHPBB', TRUE);
$phpEx = 'php';
$phpbb_root_path = './phpBB3/';
include './phpBB3/includes/startup.php';
include $phpbb_root_path . 'common.php';
include $phpbb_root_path . 'includes/functions_user.'. $phpEx;
include './phpBB3/user.php';
 
// Commence the phpBB3 user session
$user->session_begin();
$auth->acl($user->data);
$user->setup();
//Restricts access to users logged in
	//If not logged in, send them to the login page
if ($user->data['user_id'] == ANONYMOUS)
{
  header('Location: http://www.google.com');
    die();

	//This will send you to the PHPBB3 forums login page but then when you submit that it doesn't forward you to the 
	//correct location so you'd need to find that and edit it
//    login_box('', $user->lang['LOGIN']);
} 
// Instantiate the common functions of phpBB3
if (!function_exists("group_memberships"))
{
	include $phpbb_root_path . 'includes/functions_user.' . $phpEx;
}




Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3