Hi there,

I am trying to implement the below script to automate the process of logging into phpbb and am still getting
problems with header files.. I'm sure its simple maybe someone could take a look?

Code is as follows:
Index3.html: -> Where i'm taking in the username and password
Login3.php -> Where i'm calling the PHPBB_Login classes
PHPBB_Login3.php -> The modified PHPBB_Login class as posted here..

Getting the following errors

Warning: Cannot modify header information - headers already sent by (output started at c:\easyphp\www\test\includes\PHPBB_login2.php:172) in c:\easyphp\www\test\forum\includes\sessions.php on line 258

Warning: Cannot modify header information - headers already sent by (output started at c:\easyphp\www\test\includes\PHPBB_login2.php:172) in c:\easyphp\www\test\forum\includes\sessions.php on line 259

Warning: Cannot modify header information - headers already sent by (output started at c:\easyphp\www\test\includes\PHPBB_login2.php:172) in c:\easyphp\www\test\login_test\login3.php on line 26

Any help greatly appreciated..

Ps. I've tryed commenting out the header line in login3.php but i still get the same errors...

index3.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<? 
include '../includes/header.php';
?>
<table border="0" cellspacing="5" cellpadding="5">

  <tr>
    <td class="left" width="114" height="22" align="left" valign="top"><? include '../includes/menu.php'; ?></p></td>
    <td class="centrearea" width="598" align="left" valign="top">

<div id='middle'>

<?php



?>
<p>Please login using your BlastBeat Login below:</p></h3>
<form action="login3.php" method="POST">
<table align="center" border="0">
 <tr>
  <th><div align="left">
  Username:
  </div></th>
  <th>
    <div align="left">
      <input name="username" type="text" id="username">      
<br> </div></th> </tr> <tr> <th> <p align="left">Password<em> (case sensitive)</em>:</p> </th> <th> <div align="left"> <input name="user_password" type="password" id="user_password"> </div></th> </tr> <tr> <th colspan="2" align="right"> <div align="left"> <input type="submit" value="Submit"> </div> </form> <p>&nbsp;</p> <p>&nbsp;</p> </body> </html>

login3.php

<?php 
/* Example 1: Logging in place in your pages 

*/ 

$username = $_POST['username'];
$user_password = $_POST['user_password'];

require_once( '../includes/PHPBB_login2.php'); 
              //include( "./login.php"); 
              //session_start(); 

           /* First, login the user using your own login system, for example; */ 
          $user = new User(); 

           // Then login the user to the forum 
          $phpBB = new PHPBB_Login(); 

		  $user->login( $username, $user_password ); 

          $phpBB->login( $user->id ); 

          header("Location: ". "../includes/header.php"); 

?>

And finally PHPBB_Login2.php

<?php 

// Define Your User class 
// User has a method called login 
class User { 

function login($username,$password) { 
    /* 
    Process $username, $password  and ID here 

     Note that phpbb is currently using md5 encryption for passwords 
     If your members area is not encrypted then you can do a straight replacement 
     of "password" with your value or var. 
     Otherwise you will need to decrypt your password and convert it to md5 hash. 
     other encryption types are sha1, mhash and md5 

    */ 


   $password = md5( "password" ); 
   $username = "cFemailforfun"; 
   $user_id = 19; 
   $this->id = $user_id; 
} 
} 

class PHPBB_Login { 

function PHPBB_Login() { 
} 

function login( $phpbb_user_id ) { 

    define('IN_PHPBB',true); 

    // You may need to change the following line to reflect 
    // your phpBB installation. 
    $phpbb_root_path = "../forum/"; 

    global $db, $board_config; 
    global $HTTP_COOKIE_VARS, $HTTP_GET_VARS, $SID; 


    // Setup the phpbb environment and then 
    // run through the phpbb login process 

    require_once( $phpbb_root_path . "config.php" ); 

    require_once( $phpbb_root_path . "extension.inc" ); 

    require_once( $phpbb_root_path . "common.php" ); 

    return session_begin( $phpbb_user_id, $user_ip, PAGE_INDEX, FALSE, TRUE ); 

} 

function logout( $session_id, $phpbb_user_id ) { 

    define('IN_PHPBB',true); 

    // You may need to change the following line to reflect 
    // your phpBB installation. 
    $phpbb_root_path = "../forum/"; 

    global $db, $lang, $board_config; 
    global $HTTP_COOKIE_VARS, $HTTP_GET_VARS, $SID; 

    // Setup the phpbb environment and then 
    // run through the phpbb login process 

    // You may need to change the following line to reflect 
    // your phpBB installation. 
    require_once( $phpbb_root_path . "config.php" ); 

    require_once( $phpbb_root_path . "extension.inc" ); 

    require_once( $phpbb_root_path . "common.php" ); 

    session_end( $session_id, $phpbb_user_id ); 

    // session_end doesn't seem to get rid of these cookies, 
    // so we'll do it here just in to make certain. 
    setcookie( $board_config[ "cookie_name" ] . "_sid", "", time() - 3600, " " ); 
    setcookie( $board_config[ "cookie_name" ] . "_mysql", "", time() - 3600, " " ); 

} 

}//-- END of All Classed needed to loging / logout a user 
?> 

    I'm not sure on this one but you may try
    index.3.html
    Find

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <? 
    include '../includes/header.php';
    ?>
    

    Replace with

    <? 
    include '../includes/header.php';
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    

    There is something in the software you using that may want to do a redirect or is tring to send new header information

    In login3.php
    the other thing i noticed is the path to includes directory is different in the same file. It maybe dependent on realitive path of file verses relative path of included file?
    i.e.

     require_once( '../includes/PHPBB_login2.php'); 

    and

     header("Location: ". "./includes/header.php");

    Also it may help if you could tell me what the file is that your callling in the browser that generates the warnings. i.e. are you browsing directly to login2.php or are you browsing to index3.html and get the warnings on that page?

      I had the same problem and not sure if this will help but I had a space (white space?) at the ends of my code. I went through every line to check and delete spaces and everything was fine after that.

        Hi there,

        Thanks for the reply..

        I actually had the header file commented out in login3.php
        Corrected the path and made no difference..

        Also swapped the Doctype line as you said and still getting the same :/

          Removed all whitespace too and same problem..

            No problem on the index page, error only displays on login3.php
            once its called by the form on the index page..

              Just a day or so ago another user was having similar problems and he was using the Dreamweaver as his editor but on top of that he was working on a file that had been edited with another editor. There are sometimes characters placed into a document that you will not see, so as an experiment open your documents with notepad and be absolutely sure that there are no characters in any of the documents anything before the <? in any of these files might not be seen in DW or some other WYSIWYGs but will show up in notepad.

                Just another observation in login3.php
                which is used to log the user in it seems to direct them to your header.php file, normally don't you want to direct the user to the front end of your site or some other user interface page

                header("Location: ". "../includes/header.php"); 

                Your main user page calls login3.php

                <form action="login3.php" method="POST">

                This should set the cookies and then direct the user to the page you want him/her to go to with the

                header("Location: ". "../includes/header.php"); 

                It maybe that the headers that are sent in index.3.html and the fact that you are trying to redirect the user to the same header file after they login in login3.php with

                header("Location: ". "../includes/header.php"); 

                Maybe login3.php needs to be something like

                header("Location: ". "PATHTOYOURUSERPAGE/INDEX.PHP"); 

                just a thought to try???

                  Hi all,

                  Finally got this sorted! Thanks to everyone who replied.

                  I had to remove every bit of whitespace from all three files..

                  For those who are interested I have posted the (working) code below..

                  Thanks again..

                  index3.php

                  <? 
                  include '../includes/header.php';
                  ?>
                  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
                  <html>
                  <table border="0" cellspacing="5" cellpadding="5">
                  
                  <tr>
                  <td class="left" width="114" height="22" align="left" valign="top"><? include '../includes/menu.php'; ?></p></td>
                  <td class="centrearea" width="598" align="left" valign="top">
                  
                  <div id='middle'>
                  
                  <p>Please login using your BlastBeat Login below:</p></h3>
                  <form action="login3.php" method="POST">
                  <table align="center" border="0">
                  <tr>
                  <th><div align="left">
                  Username:
                  </div></th>
                  <th>
                  <div align="left">
                  <input name="username" type="text" id="username">      
                  <br> </div></th> </tr> <tr> <th> <p align="left">Password<em> (case sensitive)</em>:</p> </th> <th> <div align="left"> <input name="user_password" type="password" id="user_password"> </div></th> </tr> <tr> <th colspan="2" align="right"> <div align="left"> <input type="submit" value="Submit"> </div> </form> <p>&nbsp;</p> <p>&nbsp;</p> </body> </html>

                  login3.php

                  <?php
                  require_once( '../includes/PHPBB_login2.php');
                  include '../includes/connect_blast_phpbb.php';
                  
                  session_start();
                  
                  $username = $_POST['username'];
                  $user_password = $_POST['user_password'];
                  $user_password = md5($user_password); 
                  
                  $user = new User();
                  $user_id = $user->login( $username, $user_password ); 
                  
                  if ($user_id !== -1)
                  {
                  	// Then login the user to the forum
                  	$phpbb = new PHPBB_Login();
                  
                  $phpbb->login( $user_id );
                  
                  //echo "User should be logged in";
                  header("Location: " . "../index.php");
                  }
                  
                  else
                  {
                  
                  echo "Login Failed";
                  }
                  ?>
                  

                  PHPBB_login2.php

                  <?php 
                  // Define Your User class
                  // User has a method called login
                  
                  class User 
                  { 
                  	function login($username,$user_password) 
                  	{
                  
                  	// Authenticate the user
                  	$sql  = ("SELECT * FROM phpbb_users WHERE username='$username' AND user_password='$user_password'");
                  	$result = mysql_query($sql);
                  
                  	$login_check = mysql_num_rows($result);
                  	$contact = mysql_fetch_object ( $result );
                  
                  	// if user found
                  	if($login_check > 0) 
                  	{
                  		$user_id = $contact -> user_id;
                  		return $user_id;
                  	}
                  
                  	else 
                  	{
                  		return -1;
                  	}
                  
                  }
                  }
                  
                  class PHPBB_Login
                  {
                  
                  function PHPBB_Login(){}
                  
                  function login( $phpbb_user_id )
                  {
                  	define('IN_PHPBB',true);
                  	//You may need to change the following line to reflect
                  	// your phpBB installation.
                  	$phpbb_root_path = "../forum/";
                  	global $db, $board_config;
                  	global $HTTP_COOKIE_VARS, $HTTP_GET_VARS, $SID;
                  	// Setup the phpbb environment and then
                  	// run through the phpbb login process
                  	require_once( $phpbb_root_path . "config.php" );
                  	require_once( $phpbb_root_path . "extension.inc" );
                  	require_once( $phpbb_root_path . "common.php" );
                  	return session_begin( $phpbb_user_id, $user_ip, PAGE_INDEX, FALSE, TRUE );
                  }
                  
                  function logout( $session_id, $phpbb_user_id )
                  {
                  	define('IN_PHPBB',true);
                  	// You may need to change the following line to reflect
                  	// your phpBB installation.
                  	$phpbb_root_path = "../forum/";
                  	global $db, $lang, $board_config;
                  	global $HTTP_COOKIE_VARS, $HTTP_GET_VARS, $SID;
                  	// Setup the phpbb environment and then
                  	// run through the phpbb login process
                  	// You may need to change the following line to reflect
                  	// your phpBB installation.
                  	require_once( $phpbb_root_path . "config.php" );
                  	require_once( $phpbb_root_path . "extension.inc" );
                  	require_once( $phpbb_root_path . "common.php" );
                  	session_end( $session_id, $phpbb_user_id );
                  	// session_end doesn't seem to get rid of these cookies,
                  	// so we'll do it here just in to make certain.
                  	setcookie( $board_config[ "cookie_name" ] . "_sid", "", time() - 3600, " " );
                  	setcookie( $board_config[ "cookie_name" ] . "_mysql", "", time() - 3600, " " );
                  }
                  }
                  ?>
                  
                    7 months later

                    Hi, i am also trying to implement this but get the errors from the session_start. was any further modification made to this ?

                      I haven't a clue why PHPBB has not stoped using sessions, there really is no reason for using them except to BLOCK search engine from indexing your forum. A cookie is just fine for security and there is no reason to add sessions on top of it.

                      find the mod in PHP Mod forum that allows you to kill, distroy and delete any and all user sessions

                      CB154 wrote:

                      Hi, i am also trying to implement this but get the errors from the session_start. was any further modification made to this ?

                        so the code above uses the session_start() method. did you not implement this way ?

                          Write a Reply...