Jump to content

Cannot modify header information - headers already sent by


I Am Chris

Recommended Posts

ok well, i am very confused here, so hopefully i can find some help.

so, in this php file is the basics of my login system. it intertwines with my phpbb forum

<html>
<body>
	<!-- Header -->
	<div id="header">
		<a href="http://www.ripsense.com/"><img src="../logo.png" id="logo" alt="logo"></a>
	</div>
</body>
</html>
<?php
require ("phpbb_connect.php"); //opens acess to phpbb's user system files
    if($user->data['is_registered'])
    {
        echo 'Welcome back, ' . $user->data['username'] . '<br /><br />';
        echo '<a href="' . append_sid("{$phpbb_root_path}ucp.$phpEx") . '">' . $user->lang['PROFILE'] . '</a><br />';
        
        $l_message_new = ($user->data['user_new_privmsg'] == 1) ? $user->lang['NEW_PM'] : $user->lang['NEW_PMS'];
        $l_privmsgs_text = sprintf($l_message_new, $user->data['user_new_privmsg']);
        echo '<a href="' . append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&folder=inbox') . '">' . $l_privmsgs_text . '</a><br />';
	echo '<a href="logout.php">logout</a>';
    }
    else
    {
        $path = pathinfo($_SERVER['SCRIPT_FILENAME']);
        echo 'Welcome guest<br /><br />
            <form method="POST" action="' . $phpbb_root_path . 'ucp.php?mode=login">
            Username: <input type="text" name="username" size="20"><br />
            Password: <input type="password" name="password" size="20"><br />
            Remember Me?: <input type="checkbox" name="autologin"><br />
            <input type="submit" value="Login" name="login">
            <input type="hidden" name="redirect" value="./../' . $path['basename'] . '">
            </form>
            <br />';
        echo '<a href="' . append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=register') . '">' . $user->lang['REGISTER'] . '</a>';
    }
require ("navigation_list.html");
?>

 

now, its working perfectly for me... but only when im logged in.

the if($user->data['is_registered']) { } section is working flawlessly

but the else part is giving me the error

 

[phpBB Debug] PHP Notice: in file /includes/session.php on line 916: Cannot modify header information - headers already sent by (output started at /home/content/r/i/p/ripsense/html/index.php:9)

that file is linked too by the php_connect.php

 

it absolutely makes no sense to me why i would only get that error when im logged out. only the else is having the problem, i don't get it at all, saying that both the if and the else use the same file.. thats called for near the top of the page

 

does anybody have any idea why this is happening?

ty

Link to comment
Share on other sites

a header can not be sent if there is anything outputted before it.

 

yes but, wouldn't i have that problem still when

  if($user->data['is_registered'])

is true?

i don't understand why i'm  only having the problem when its calling the else statement

am i missing something?

 

you can see it here.. if it madders

www.ripsense.com

i removed the nav bar so you can see the login links...

if you login with username: test password: test1

you'll see that the problem disappears..

then if you logout again

the problem comes back

 

hmm, on further inspection, the problem dosen't occur when your not logged on, it accurs after the redirection from the logout..

 

Link to comment
Share on other sites

I think we need to see something to do with session.php.

Can we see line 915 - 917

 

well thats part of the phpbb forum

 

header('Set-Cookie: ' . $name_data . (($cookietime) ? '; expires=' . $expire : '') . '; path=' . $config['cookie_path'] . $domain . ((!$config['cookie_secure']) ? '' : '; secure') . '; HttpOnly', false);

}

 

um

like i said tho, it only happens after the redirection from logging out..

so i'll start off here as logged out (http://www.ripsense.com/)

login, and i get re-directed, now here

(http://www.ripsense.com/index.php?sid=5e843631d196767c460555571e447fcb)

then i logout, now here (http://www.ripsense.com/) with the error...

it makes no sense -.-

 

is there something wrong with my logout.php?

<?php
require ("phpbb_connect.php");

  if($user->data['is_registered'])
{
    $user->session_kill();
    $user->session_begin();

    $redirect = request_var('redirect', "index.$phpEx");
    $url = redirect($redirect, true);
    $time = 0;    //Seconds to wait before redirect
   
    echo '<meta http-equiv="refresh" content="' . $time . ';url=' . str_replace('&', '&', $url) . '" />';
   
   
}

else
{
    trigger_error('LOGOUT_FAILED');
}
?>

 

php_connect.php is this

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

    // Start session management
    $user->session_begin();
    $auth->acl($user->data);
    $user->setup('ucp');
?>

 

Link to comment
Share on other sites

Try this:

 

<?php require ("phpbb_connect.php"); //opens acess to phpbb's user system files ?>
<html>
<body>
	<!-- Header -->
	<div id="header">
		<a href="http://www.ripsense.com/"><img src="../logo.png" id="logo" alt="logo"></a>
	</div>
</body>
</html>
<?php

    if($user->data['is_registered'])

Link to comment
Share on other sites

Try this:

 

<?php require ("phpbb_connect.php"); //opens acess to phpbb's user system files ?>
<html>
<body>
	<!-- Header -->
	<div id="header">
		<a href="http://www.ripsense.com/"><img src="../logo.png" id="logo" alt="logo"></a>
	</div>
</body>
</html>
<?php

    if($user->data['is_registered'])

 

na, same error, except now it shows up b4 the picture.

i think what it is doing is setting header, then setting again after redirecting from logout page..

is there any way to destroy header info so to set it again?

or am i way off?

Link to comment
Share on other sites

All this....

 

<html>
<body>
	<!-- Header -->
	<div id="header">
		<a href="http://www.ripsense.com/"><img src="../logo.png" id="logo" alt="logo"></a>
	</div>
</body>
</html>

 

Is output. You cannot call header after output has been sent to the browser. You need to arrange your code accordingly.

Link to comment
Share on other sites

From what I;ve seen when I visited the url given, header is send more than once.

 

Try this function to block sending headers more than once:

http://www.php.net/headers_sent

 

hmm

i think that was it, its what made sense to me..

but i the pbp_connect.php into the logout file insted of calling it too it.

i don't understand why... but it worked

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.