Error : Unable to add cookies, header already sent.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nirvana43
    New Member
    • Oct 2007
    • 29
    • 3.6.x

    Error : Unable to add cookies, header already sent.

    Hello
    I've created 1 custom page by referring to vBulletin API Basics topic posted by Psionic Vision.
    Here is topic url : http://www.vbulletin.org/forum/showthread.php?t=98009
    I'm getting following error :
    Unable to add cookies, header already sent.
    File: /home2/aditya43/public_html/forums/test.php
    Line: 1
    My test.php file contains following code :
    <?php
    error_reporting(E_ALL & ~E_NOTICE);
    define('NO_REGISTER_GLOBALS', 1);
    define('THIS_SCRIPT', 'adi');
    $globaltemplates = array('adi');
    require('./global.php');
    include('aaa/tmp.php');
    $navbits = array();
    $navbits[$parent] = 'Aditya Test Page';
    $navbits = construct_navbits($navbits);
    eval('$navbar = "' . fetch_template('navbar') . '";');
    if (!$vbulletin->userinfo['userid'])
    {
    print_no_permission();
    }
    else
    {
    eval('print_output("' . fetch_template('adi') . '");');
    }
    ?>
    My template "adi" under vbulletin contains following code :
    $stylevar[htmldoctype]
    <html dir="$stylevar[textdirection]" lang="$stylevar[languagecode]">
    <head>
    <title>$vboptions[bbtitle]</title>
    $headinclude
    </head>
    <body>
    $header
    $navbar
    <if condition="$adiinitcond">
    $testcond1
    <else/>
    $testcond2
    </if>
    </table>
    $footer
    </body>
    </html>
    tmp.php file contains :
    $a=5;
    $b=6;
    $adiinitcond="$a>$b";
    $testcond1="$a is bigger";
    $testcond2="$b is bigger";
    However if i login to vbulletin forum and then access test.php, it works perfect. But as a guest it gives me above error.
    I also wanna allow guests on test.php or at least it should print vbulletin error message.

    Here is what i've done so far to get rid of above error :
    1. Removed all whitespace etc.
    2. Tried "<?php" tag without closing php tag "?>"
    3. Tested after removing "include('aaa/tmp.php');" from test.php
    4. Removed all "echo", "print" etc. from tmp.php

    The possible cause of above error is i'm trying to send data or something to browser before vbulletin cookies. So i traced my entire code and found i'm not sending anything to browser before cookies (or am i?).
  • Lynne
    Former vBulletin Support
    • Oct 2004
    • 26255

    #2
    You should be posting this over at vb.org where they deal with custom coding.

    You should try giving no permission *before* you eval any templates (like your navbar).

    If you need further help, you should post this over at vb.org.

    Please don't PM or VM me for support - I only help out in the threads.
    vBulletin Manual & vBulletin 4.0 Code Documentation (API)
    Want help modifying your vbulletin forum? Head on over to vbulletin.org
    If I post CSS and you don't know where it goes, throw it into the additional.css template.

    W3Schools &lt;- awesome site for html/css help

    Comment

    widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
    Working...