Membership Plugin PHP8
4 posts by 3 authors in: Forums > CMS Builder
Last Post: May 24, 2022 (RSS)
By dbown - May 20, 2022
I have some code that I used in the Website Membership Plugin that work in PHP 7.3 but not in 8.0.
When using PHP 8.0, when a user logs out of the website the following message appears...
<START>
Warning: Trying to access array offset on value of type bool in /home1/XXXXX/public_html/client-area.php on line 18 Fatal error: setPrefixedCookie: Can't set cookie(lastUrl, https://www.XXXXX.com/client-area.php), headers already sent! Output started in /home1/XXXXX/public_html/client-area.php line 18. in /home1/XXXXX/public_html/cmsb/lib/http_functions.php on line 292
<END>
The code on the top of the page is as follows:
<START>
<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
// load viewer library
$libraryPath = 'cmsb/lib/viewer_functions.php';
$dirsToCheck = array('/home/eeltd3/public_html/','','../','../../','../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }
if (!@$GLOBALS['WEBSITE_MEMBERSHIP_PLUGIN']) { die("You must activate the Website Membership plugin before you can access this page."); }
// error checking
$errorsAndAlerts = alert();
if (@$CURRENT_USER) { $errorsAndAlerts .= "You are already logged in! <a href='https://www.XXXXXX.com/client-area.php'>Click here to continue</a> or <a href='?action=logoff'>Logoff</a>.<br/>\n"; }
if (!$CURRENT_USER && @$_REQUEST['loginRequired']) { $errorsAndAlerts .= "Please login to continue.<br/>\n"; }
// save url of referring page so we can redirect user there after login
// if (!getPrefixedCookie('lastUrl')) { setPrefixedCookie('lastUrl', @$_SERVER['HTTP_REFERER'] ); }
$CompName = $CURRENT_USER['fullname'];
// load records from 'documents'
list($documentsRecords, $documentsMetaData) = getRecords(array(
'tableName' => 'documents',
'loadUploads' => true,
'allowSearch' => false,
'where' => "title = '$CompName'",
));
?>
<?php if (!$CURRENT_USER) { websiteLogin_redirectToLogin(); } ?>
<END>
Hopefully that is enough to go on for you to help me fix this issue.
Thanks,
Dave
By gkornbluth - May 20, 2022
Hi Dave,
I don't know if it will help but there are a number of posts that come up when you do a search for: headers already sent!. There's one post that suggests:"The first thing I'd do would be to check through the plugin files to see if there are any blank lines either at the very top or the very bottom of files. Often this problem is caused by an extra blank line after the ?> at the bottom of a PHP file."
Also check my posts from that search and look at the answers at the end of each.
Basically, when I encountered some pages that threw a 'header' error, I solved the problem by taking another working page, making a copy of it, and then replacing everything except for the load viewer library and get records calls with the page code which originally caused the error, which in your case is the rest of the code from your client-area.php page.
Since you're setting an HTTP-header : you must not have sent any kind of output before (not even a blank space at the end of an included file) or at the beginning of the page code. If you do you'll throw a "Warning: Cannot modify header information - headers already sent" error. Test your page after the modification to make sure that it works as planned, and proceed
accordingly.
The rub is that those blank spaces may not show up in your particular code editor.
My other post describes another possible solution offered by Dave Edis
Just make a backup of your original client-area.php page before you make any changes.
Hope that all makes sense and that it helps,
Jerry Kornbluth
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
By daniel - May 24, 2022
Hi Dave,
The error is being caused by this line:
$CompName = $CURRENT_USER['fullname'];
It is being referenced before the page checks to see if the user is logged in (this is what creates the $CURRENT_USER array). So a simple fix would be to move this line that checks for a logged-in user:
<?php if (!$CURRENT_USER) { websiteLogin_redirectToLogin(); } ?>
And move it above the line at issue:
if (!$CURRENT_USER) { websiteLogin_redirectToLogin(); }
$CompName = $CURRENT_USER['fullname'];
Let me know if that fixes the issue, or if you have any other questions!
Thanks,
Technical Lead
interactivetools.com