Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
0 votes
1.6k views
in Q2A Core by
edited by

Update: Error is caused by the badges plugin (v4.1) :(
Issue reported at: https://github.com/NoahY/q2a-badges/issues/22

Probable solution: https://github.com/NoahY/q2a-badges/issues/22#issuecomment-12112784
→ replace "qa_cookie_get_create()" with "qa_cookie_get()"

Thank you, and good luck in Canada if you decide to go there.
Greetings Kai
 

You may skip the following text, and check my last comment below instead!
 



I reported twice (1 | 2 detailed) about a PHP Warning that appeared in my server logs every day:

PHP Warning:  Cannot modify header information - headers already sent by (output started at /qa-include/qa-theme-base.php:106) in /qa-include/qa-app-cookies.php on line 61

After 9 months, well, I found the time to investigate the issue.

As gidgreen said, I checked all possible calls of function output_raw(...) that is on line 106 in qa-theme-base.php.

Here is what I found:

1. custom-theme/qa-theme.php
When overwriting:
  function sidepanel() {
  ...
  $this->output_raw(@$this->content['sidepanel']);
  ... }

2. qa-include/qa-theme-base.php
Line 99:         function output_raw($html)
Line 261:                     $this->output_raw($scriptline);
Line 290:                     $this->output_raw($line);
Line 338:                 $this->output_raw($this->content['body_header']);
Line 344:                 $this->output_raw($this->content['body_footer']);
Line 403:             $this->output_raw($notice['content']);
Line 578:             $this->output_raw(@$this->content['sidepanel']);
Line 590:                 $this->output_raw($sidebar);
Line 709:                 $this->output_raw($part);
Line 1327:                 $this->output_raw($q_item['content']);
Line 1768:                 $this->output_raw($q_view['content']);
Line 1918:             $this->output_raw($a_item['content']);
Line 1999:             $this->output_raw($c_item['content'])
 

As you can see only $this->output_raw(@$this->content['sidepanel']); holds an @ sign before $this. All other occurrences do not have this @ sign.

In my advanced/custom theme I commented out the line:

// $this->output_raw(@$this->content['sidepanel']);

as there is no content to display.

The error disappeared (for already 30 hours, still waiting if...) → Update: Error appeared later on again :o(

 

Helping to find the bug:

output_raw() of $this->output_raw(@$this->content['sidepanel']); in my custom theme is accessing the following database entries:

qa-page.php, line 464:
'sidepanel' => qa_opt('show_custom_sidepanel') ? qa_opt('custom_sidepanel') : null,

I checked my database entries (same like going to >admin >layout):

#title: custom_sidepanel
#content: <iframe src="rss2html/out.php" style="width:180px;height:220px;border:0;"></iframe>

#title: show_custom_sidepanel
#content: 0

As you see I have some content defined, but not used it (show_custom_sidepanel=0).

Maybe this fact is somehow interfering with the @-sign above (the 'surpresser' of errors).

Hope that helps.

Kai

 

Q2A version: 1.5.3
by
Update: Error appearead again :(
I will check the logs tomorrow to finally try to find out what's wrong...
by
Update: In function output_raw() instead of using:
echo str_repeat("\t", max(0, $this->indent)).$html."\n";
I tried: echo $html;

Nevertheless, the error appeared again! ... So it is not str_repeat but the passed $html which is causing problems.

Next I try to check, if $html is really a string, maybe this will help:
if (is_string($html) && strlen($html))
by
edited by
if (is_string($html) && strlen($html)) ... did not help either.

I think I have to give up... this actually leads to the conclusion that it is not the function output_raw().

--
It must be the passed $html that must be wrong somehow. As I only used the core - without plugins neither adv. theme calling output_raw() - I still think it is core or the "content" that is passed to the core. Maybe it is a "unicode" problem? ... Which parameters/content passed to output_raw() from qa-theme-base could change and are not static?

This is really bugging me.
--

Or it is the qa_cookie_get_create() that gidgreen mentioned which is called by: qa-page-ask.php, qa-page-question-submit.php, qa-plugin/badges/qa-badge-check.php, qa-plugin/badges/qa-plugin.php, and qa-plugin/wysiwyg-editor/qa-wysiwyg-upload.php
by
BINGO! It is probably the BADGES plugin!

I checked my last error and checked the qa_eventlog table, both TIMES match! yes, a trace =)

I checked another time of event "badge_awarded" against error time, BINGO 2.

Finally, we got'em!

1 Answer

0 votes
by
edited by

One of the 2 lines (or both?) is causing the error calling qa_cookie_get_create()

1. https://github.com/NoahY/q2a-badges/blob/master/qa-badge-check.php#L627

2. https://github.com/NoahY/q2a-badges/blob/master/qa-plugin.php#L225

Issue @github: https://github.com/NoahY/q2a-badges/issues/22


I analyzed the badges causing the error, these are the ones:

badge_slug=notable_question
badge_slug=popular_question
badge_slug=reader
badge_slug=avid_reader

 

--

The following code change did not solve the issue.

In qa-plugin.php I am using now from line 220:

$handle = qa_getHandleFromId($uid);

// added 2 lines and changed mysql statement below replacing qa_cookie_get_create() with $cookieid
$userid=qa_get_logged_in_userid();
$cookieid=isset($userid) ? qa_cookie_get() : qa_cookie_get_create(); // create a new cookie if necessary

qa_db_query_sub(
    'INSERT INTO ^eventlog (datetime, ipaddress, userid, handle, cookieid, event, params) '.
    'VALUES (NOW(), $, $, $, #, $, $)',
    qa_remote_ip_address(), $uid, $handle, $cookieid, 'badge_awarded', 'badge_slug='.$badge_slug.($oid?"\t".'postid='.$oid:'')
);

In qa-badge-check.php I am using now from line 622:

$handle = qa_getHandleFromId($user_id);

// added 2 lines and changed mysql statement below
$userid=qa_get_logged_in_userid();
$cookieid=isset($userid) ? qa_cookie_get() : qa_cookie_get_create(); // create a new cookie if necessary

qa_db_query_sub(
    'INSERT INTO ^eventlog (datetime, ipaddress, userid, handle, cookieid, event, params) '.
    'VALUES (NOW(), $, $, $, #, $, $)',
    qa_remote_ip_address(), $user_id, $handle, $cookieid, 'badge_awarded', 'badge_slug='.$badge_slug.($object_id?"\t".'postid='.$object_id:'')
);`

Posted at github as well.

...