Headers already sent errrors if not logged in.

8 posts by 2 authors in: Forums > CMS Builder
Last Post: September 19, 2022   (RSS)

Hi Jerry,

What is the code at line 77 of /home3/mrqsygmy/public_html/_website_init.php line 77? This is where the error indicates the early output is happening. 

Daniel
Technical Lead
interactivetools.com

By gkornbluth - September 19, 2022 - edited: September 20, 2022

Hey Daniel,

Again thanks for checking on this.

When I delete everything below the load records calls in _website_init, (starting at line 77)  the error message points to the 'include'  line in the provider profile file (line 7).

I've already tried inserting the load viewer function and load records directly into some of the files that exhibit the issue and the error still remains only when logged off.

You can see the issue at https://dbtproviders.com/provider_profile.php, and at https://dbtproviders.com/providers_emaillist.php, as examples

Hope I'm making sense.

Thanks,

Jerry

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
Attachments:

_website_init.php 6K

Hey Jerry,

I can see that there's a space after the "?> " on line 7 in provider_profile.php - whitespace will count as "output" and cause this error. To make things as simple as possible, I'd suggest moving the login check to be immediately after the include, like this:

include ("_website_init.php"); 
if (!$CURRENT_USER) { websiteLogin_redirectToLogin(); }
?>

Also, PHP tags that look like this could be outputting a newline which I assume is also being counted as output:

?>
<?php

This shows up a number of times in _website_init.php starting on line 76-77, so I would suggest rewriting the whole file to exist in a single PHP block like this:

//...

list($faqRecords, $faqMetaData) = getRecords(array(
    'tableName'   => 'faq',
    'loadUploads' => true,
    'allowSearch' => false,

  ));

$masterurl = $common_informationRecord['master_url'];

if ($image_libraryRecord['image_1']):
  foreach ($image_libraryRecord['image_1'] as $index => $upload):
    $image1 = $upload['thumbUrlPath2'];
  endforeach;
endif;

// etc, etc.

or simply remove the newlines so there's no space between PHP tags, like this: "?><?php"

Let me know if that helps, or if you have any further questions.

Thanks!

Daniel
Technical Lead
interactivetools.com

Thanks Daniel, I really appreciate a second set of (expert) eyes.

I'll let you know the outcome

I'm surprised though that it only kicked in when logged out.

Jerry

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By gkornbluth - September 19, 2022 - edited: September 19, 2022

Well, I'm embarrassed, and a bit confused.

I rewrote the _website_init so that it was 1 block of php code, changed the placement of the if (!$CURRENT_USER) { websiteLogin_redirectToLogin(); } and everything seems to work.

The confusing part is that I use the same _website_init file on many of my sites and never seemed to have the same issue.

Oh well, better go back and check all the other sites again...

I've not used the shorthand code below before, and just to be on the safe side, could you tell me if I've formatted it correctly?

Thanks,

Jerry

  list($faqRecords, $faqMetaData) = getRecords(array(
    'tableName'   => 'faq',
    'loadUploads' => true,
    'allowSearch' => false,

  ));
$masterurl = $common_informationRecord['master_url'];
if ($image_libraryRecord['image_1']){
foreach ($image_libraryRecord['image_1'] as $index => $upload): 
$image1 = $upload['thumbUrlPath2'];
endforeach;} 
if ($image_libraryRecord['image_2']){
foreach ($image_libraryRecord['image_2'] as $index => $upload): 
$image2 = $upload['thumbUrlPath2']; 
endforeach;} 
if ($image_libraryRecord['image_3']){
foreach ($image_libraryRecord['image_3'] as $index => $upload): 
$image3 = $upload['thumbUrlPath2']; 
endforeach;} 
if ($image_libraryRecord['image_4']){
foreach ($image_libraryRecord['image_4'] as $index => $upload): 
$image4 = $upload['thumbUrlPath2'];
 endforeach;}
if ($image_libraryRecord['image_5']){
foreach ($image_libraryRecord['image_5'] as $index => $upload): 
$image5 = $upload['thumbUrlPath2'];
endforeach;}
if ($image_libraryRecord['image_6']){foreach ($image_libraryRecord['image_6'] as $index => $upload):
$image6 = $upload['thumbUrlPath2'];
 endforeach;}
if ($image_libraryRecord['image_7']){
foreach ($image_libraryRecord['image_7'] as $index => $upload): 
$image7 = $upload['thumbUrlPath2'] ?><?php endforeach;}
if ($image_libraryRecord['image_8']){foreach ($image_libraryRecord['image_8'] as $index => $upload):
$image8 = $upload['thumbUrlPath2'];
endforeach;} 
if ($image_libraryRecord['image_9']){ foreach ($image_libraryRecord['image_9'] as $index => $upload): 
$image9 = $upload['thumbUrlPath2'];
endforeach;}
if ($image_libraryRecord['image_10']){foreach ($image_libraryRecord['image_10'] as $index => $upload): 
$image10 = $upload['thumbUrlPath2'];
endforeach;} 
if ($image_libraryRecord['image_11']){ foreach ($image_libraryRecord['image_11'] as $index => $upload):
$image11 = $upload['thumbUrlPath2']; 
endforeach;} 
if ($image_libraryRecord['image_12']){
foreach ($image_libraryRecord['image_12'] as $index => $upload): 
$image12 = $upload['thumbUrlPath2']; 
endforeach;} 
$placeHolders = array("*img1*", "*img2*", "*img3*", "*img4*", "*img5*", "*img6*", "*img7*", "*img8*", "*img9*", "*img10*", "*img11*", "*img12*");
$replaceWith = array(@$image1, @$image2, @$image3, @$image4, @$image5, @$image6, @$image7, @$image8, @$image9, @$image10, @$image11, @$image12 ); ?>
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Hey Jerry,

Yes, that formatting looks correct! There is one "?><?php" remaining that you can remove, but it's pretty inconsequential.

The confusing part is that I use the same _website_init file on many of my sites and never seemed to have the same issue.

Oh well, better go back and check all the other sites again...

There is a setting that can help PHP ignore some premature output, but I've found it to not always be 100% reliable, and it can be site/server-dependent, so there may be some difference between this environment and other sites where it's been used. In any case, I find it best practice to just remove any unnecessary whitespace to keep code as portable as possible.

Let me know if you have any further issues!

Thanks,

Daniel
Technical Lead
interactivetools.com

Hey Daniel,

Got the rogue ?><?php.

Really glad you could help solve the  issue.

I'll go ahead and have my crow stew dinner now.

Thanks again!

Jerry

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php