Newsletter Builder Header Conflict?

Hello, All

I'm having a few niggles with NLB - the most pressing being the one shown below in an error message. The error is trigered every time a user is taken to the page to confirm their newsletter subscription:

Sep 14th, 2015 - 09:43:40 PM
E_WARNING: Cannot modify header information - headers already sent by (output started at /homepages/htdocs/webby/index.php:14)
/homepages/htdocs/webby/cmsb/plugins/newsletterBuilder/newsletterBuilder.php (line 64)
http://www.webby.uk/subscribe?o=1&m=11&n=&num=33

The offending line 64 in newsletterBuilder.php is hi-lighted below:

function nlb_frontend_trackOpens() {
if (!@$_REQUEST['o']) { return; }

nlb_log(@$_REQUEST['m'], @$_REQUEST['n'], '5');
header('Content-Type: image/gif');
echo base64_decode('R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'); // 1x1 transparent gif
exit;
}

Unlike the normal NLB set-up - which uses is a separate subscribe.php page - my subscription page uses the site's generic index.php page. The subscribe code is inserted via an include when viewing the page. The index.php page already has a header - so clearly there is some sort of conflict occurring. How can I get rid of the problem?

:0/

Perch

Hi, Greg -

Thanks for your input. I know what you say is correct but I'm not sure how to resolve it.

The code at the very top of my index.php page looks like this:

<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
$libraryPath = 'cmsb/lib/viewer_functions.php';
$dirsToCheck = array('/etc/','','../','../../','../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }
$doc = $_SERVER['DOCUMENT_ROOT']."/";
$path = 'inc.';
?>

<?php include $doc.$path."code/init.common.php"; ?> /* Default init code */

<?php include $doc.$path."code/initInc.".$selectedPage['initInc'].".php"; ?>  /* Page specific init code */

This code usually works fine for everything - included pretty much all the standard iTools plugins.

In the instance of the Newsletter page, the code from subscribe.php (below) would be included with the hi-lighted code shown above.

<?php
// error checking
if (!@$GLOBALS['NEWSLETTER_BUILDER_PLUGIN']) { die("You must activate the newsletter plugin to see this page."); }
list($errorsAndAlerts, $lists, $authUserNum, $authUserEmail) = nlb_frontend_dispatcher3();
?>

Are you saying that this code is being include too late in the sequence? If so, how would I conditionally insert it at a higher point?

Perch

Hey Perch,

That's correct, the code is loading after content starts to appear on the page, and that's whats causing the problem. What about something like this:

<?php

  header('Content-type: text/html; charset=utf-8'); 

  $libraryPath = 'cmsb/lib/viewer_functions.php';
  $dirsToCheck = array('/etc/','','../','../../','../../../');
  foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
  if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }
  

  $doc  = $_SERVER['DOCUMENT_ROOT']."/";
  $path = 'inc.';

  include $doc.$path."code/init.common.php"; 

  if(@$selectedPage['initInc'] == 'subscribe'){
    if (!@$GLOBALS['NEWSLETTER_BUILDER_PLUGIN']) { die("You must activate the newsletter plugin to see this page."); }
    list($errorsAndAlerts, $lists, $authUserNum, $authUserEmail) = nlb_frontend_dispatcher3();
  }

So if the selected page is settings, then we load newsletter dispatcher code. There are a few assumptions I've made here:

  • The $selectedPage variable is created in init.common.php
  • init.common.php doesn't load any content on the page. 
  • That the correct initInc variable to load the newsletter is subscribe.

Thanks,

Greg

Greg Thomas







PHP Programmer - interactivetools.com

Hi, Greg -

Thanks for your help with this. Unfortunately, your solution won't help because that's exactly the way the code works at the moment! I left the conditional element out of my example above to make it simpler.

That means the problem must be the code being loaded by the init.common.php include in the preceding step. I don't think the code includes any "content" as such. It's mainly getRecords() calls and code to control which pages to load.

What else constitutes "content"?

:0/

Perch

Hey Perch,

All space that isn't inside of PHP tags is considered content. So for this code:

<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
$libraryPath = 'cmsb/lib/viewer_functions.php';
$dirsToCheck = array('/etc/','','../','../../','../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }
$doc = $_SERVER['DOCUMENT_ROOT']."/";
$path = 'inc.';
?>

<?php include $doc.$path."code/init.common.php"; ?> /* Default init code */

<?php include $doc.$path."code/initInc.".$selectedPage['initInc'].".php"; ?>  /* Page specific init code */

The two empty lines on 10 and 12 would be considered content as well as the comments you've added.

In the code example I provided in my previous post all of the code is inside of one set of PHP tags, and there is no white space. Setting your code up like that will hopefully resolve the issue. 

Cheers,

Greg

Greg Thomas







PHP Programmer - interactivetools.com