0

I have received these errors:

[phpBB Debug] PHP Warning: in file [ROOT]/includes/session.php on line 1042: Cannot modify header information - headers already sent by (output started at /home4/ink/public_html/testpage.php:3)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/session.php on line 1042: Cannot modify header information - headers already sent by (output started at /home4/ink/public_html/testpage.php:3)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/session.php on line 1042: Cannot modify header information - headers already sent by (output started at /home4/ink/public_html/testpage.php:3)

I have searched for the following solutions: - Using a non-UTF file format - Using header(location 'www.example.com') - Clearing blank spaces before or after php tag - Putting the php session starts at the beginning of all files, and other areas

I am trying to provide a login area, utilizing the phpBB database for usernames and passwords. The following code works once you have visited the forums, but until then, it spits out the error above.

Here is the code.

<?php   
define('IN_PHPBB', true);
$phpbb_root_path = './forum/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);

$user->session_begin();
$auth->acl($user->data);
$user->setup(); 
if($user->data['is_registered'])
{

    echo "Hello " . $user->data['username']; //User is already logged in

    echo "<br /> Last visit: " . $user->format_date($user->data['session_last_visit']);

}

else
{

    echo '<form method="POST" action="./forum/ucp.php?mode=login">
    <p>Username: <input type="text" name="username" size="40"><br />
    Password: <input type="password" name="password" size="40"><br />
    Remember Me?: <input type="checkbox" name="autologin"><br /><br /><br />
    <input type="submit" value="Submit" name="login"></p>
    </form>';
}?>

This code is used in the menu area of the site. The code above is found in an include, which is used across the entire site.

From my searching to figure out an answer, I feel the solution is going to involve putting parts of the code in a file before the rest of the site is called, so that the session can start first before anything else. If so, I would love some insight on how to go about this, and if not, then that would be why I have been unable to solve this!

I looked through all of the stack overflow question with this error, and I couldn't find a workable solution in any of them. Nor did phpBB's documentation assist in specifying more about this header issue.

If more info is needed, ask away!

AstroCB
  • 12,337
  • 20
  • 57
  • 73
Justin
  • 1
  • 1
  • What's in `/home4/ink/public_html/testpage.php`, on line 3? – andrewsi Oct 03 '13 at 15:51
  • I didn't find that thread via Google or the search, but I read it over, and it still doesn't really explain what I need to do. Line's 1 to 5 of testpage.php:
    – Justin Oct 03 '13 at 16:56

2 Answers2

0

This is the session problem

You need to start session at the top of the file..

<?php
    session_start();
    // then your code
Sumit Bijvani
  • 8,154
  • 17
  • 50
  • 82
  • My site uses php includes. So for each page/file, I would need to put the suggested code at the top, first? Can I use a php include to this code, and then include that code to each file? Every page uses an include to link the menu html, the content...etc. My question is can I use a php include first, or does the above code need to be used before any includes are used? If so, how would I go about implementing this into a site with 100+ pages? – Justin Oct 03 '13 at 16:58
0

Cookies are sent in the headers of the transmission of the HTTP page. Once you give some output, you cannot modify these anymore.

buffer your output useing ob_start(); at the to of the page

user2092317
  • 3,226
  • 5
  • 24
  • 35
  • In one of the threads it was stated that this was 'hiding the problem', and not fixing it. Although I may know the cause of the issue, I still do not know why it is occurring, and how to actually fix it. I'd prefer a solution that doesn't have a lot of 'hate' around it for being unprofessional, and a last resort! Thanks! – Justin Oct 03 '13 at 17:00