Newsletter Builder Header Conflict?

By gregThomas - September 16, 2015

Hey Perch,

The problem is that the index is displaying content on the page before the subscription functions run. So when the mailer tries to set the header it can't, as it's already started loading the page. 

If you update your index page so that the subscription functionality runs before any content appears on the page the issue should be resolved. 

Cheers,

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By Perchpole - September 16, 2015

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

By gregThomas - September 16, 2015

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

By Perchpole - September 17, 2015

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

By gregThomas - September 17, 2015

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