Error with Website Membership plugin

18 posts by 2 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: May 30, 2020   (RSS)

By daniel - May 26, 2020

Hi Andreas,

Thanks for those examples - I think I see that the issue is, essentially, that there is page output before the viewer library is being loaded.

For your first example, you may be able to fix this by placing the viewer library portion above your HTML:

<?php
// load viewer library
$libraryPath = 'registry/lib/viewer_functions.php';
$dirsToCheck = ['','../','../../','../../../','../../../../'];
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Number of cases</title>
</head>
<body>

<font color=#000000>
Currently, <b>
<?php
...

For the second example, I assume that this is contained in a WP template that loads within the page's body and has header HTML above it. Even though your WP and CMSB folders are separated, if WP is printing any HTML to the page before CMSB tries to load it can cause this issue. We haven't done much testing in the way of integrating WP and CMSB, but I have come up with a quick solution that may help in your case. In your theme's functions.php file, add the following (make sure to change the $libraryPath variable to match your installation):

add_action('init', 'cmsb_load_viewer');
function cmsb_load_viewer() {
  
  // load viewer library
  $libraryPath = 'path/to/your/cmsb/lib/viewer_functions.php';
  $dirsToCheck = array('','../','../../','../../../', '../../../../');
  foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}

}

The above should make the viewer library available on all front-end WP pages. Then, in your WP template, place this line to make sure CMSB is loaded:

<?php 

  if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }
  
?>

Though, be aware that any direct modification to theme files can be overwritten by updates if you're not using a child/custom theme.

I hope the above is helpful - let me know if you make any progress or if you have any more questions.

Thanks!

Daniel
Technical Lead
interactivetools.com

By andreasml - May 27, 2020

Hello Daniel

Thank you for your quick reply. I checked the solution on the first example and unfortunately it caused the same problem again.

I played a bit with the php script and this is what i found. 

1. When I insert a simple php script like the following, there is no problem. 

<?php
echo "Hello world";
?>

2. When I insert a php script with just the viewer library part of the script (as it follows) the problem comes up again. 

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

3. When the php contains only the first part (as seen below) of the script, again there is no problem. 

<?php
// load viewer library
$libraryPath = 'registry/lib/viewer_functions.php';
$dirsToCheck = ['','../','../../','../../../','../../../../'];
?>

4. As a conclusion, I think that the conflict exists with the following part of the code. 

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

I do not know if this makes any sense, but I hope that it might help you a bit.

Regards,

Andreas

PS.

1. I have not made yet the changes you mentioned for the second of my examples. I will give you my feedback when i will have done it.

2. Just to underline that this problem appeared suddenly out of the blue, after it had worked flawlessly with the same WP theme for quite a long time.

By daniel - May 28, 2020

Hi Andreas,

Thanks for the follow-up. It does confirm my thought that the issue is caused at the point where the viewer library is included.

1. I have not made yet the changes you mentioned for the second of my examples. I will give you my feedback when i will have done it.

Yes - let me know how this goes. I think this is the best initial direction for getting the issue resolved.

2. Just to underline that this problem appeared suddenly out of the blue, after it had worked flawlessly with the same WP theme for quite a long time.

This part is a bit more difficult to figure out, though there are many things that can change on a website or its server that can impact seemingly unrelated functions. I think ultimately it'll be most efficient to focus on how to get it working from here, rather than trying to narrow down why it started happening.

Cheers,
Daniel

Daniel
Technical Lead
interactivetools.com

By andreasml - May 28, 2020

Hi Daniel

Short question: I am trying to follow your second suggestion. I put the first part in the end of the functions.php file of the WP theme I am using. I do not know where should I place the second part

<?php 

  if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }
  
?>

Where exactly should I place it? Inside the functions.php file again or in somewhere else?

Regards

Andreas

By andreasml - May 28, 2020

Hi Daniel

Thank you again. The problem was solved for most of the php scripts!!  

Unfortunately, I cannot make it work when a use a login php script (login to CMSB). I use the following code:

<?php
  
  // load viewer library
  $libraryPath = 'registry/lib/viewer_functions.php';
  $dirsToCheck = array('/var/www/vhosts/vascularregistry.gr/httpdocs/','','../','../../','../../../');
  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='{$GLOBALS['WEBSITE_LOGIN_POST_LOGIN_URL']}'>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'] ); }
$GLOBALS['WEBSITE_LOGIN_POST_LOGIN_URL'] = PREFIX_URL.'/registry/';
?>


<h3>Login to HEVAR Portal</h3> 
<!-- USER LOGIN FORM -->
  <?php if (@$errorsAndAlerts): ?>
    <div style="color: #C00; font-weight: bold; font-size: 13px;">
      <?php echo $errorsAndAlerts; ?><br/>
    </div>
  <?php endif ?>

<?php if (!@$CURRENT_USER): ?>
  <form action="?" method="post">
  <input type="hidden" name="action" value="login" />

  <table border="0" cellspacing="0" cellpadding="2">
   <tr>
    <!-- <td>Username</td> -->
    <td><input type="text" name="username" value="<?php echo htmlencode(@$_REQUEST['username']); ?>" size="30" placeholder="Username or Email&hellip;" autocomplete="on" /></td>
   </tr>
   <tr>
  <!-- <td>Password</td> -->
    <td><input type="password" name="password" value="<?php echo htmlencode(@$_REQUEST['password']); ?>" size="30" placeholder="Password&hellip;" autocomplete="on" /></td>
   </tr>

   <tr>
    <td style="text-align:left">
      <br/><input type="submit" name="submit" value="Login" />
      <a href="https://vascularregistry.gr/registration/" target=_parent>or sign-up</a><br/><br/>
      
      <?php if (function_exists('fbl_login')): // NOTE: This feature requires the Facebook Login v2+ plugin! ?>
        <?php fbl_loginForm_javascript(); ?>
        <a href="#" onclick="fbl_login(); return false;">Login with Facebook</a><br/><br/>
      <?php endif; ?>
      
      <?php if (@$GLOBALS['TWITTERAPI_ENABLE_LOGIN']): ?>
        <a href="<?php echo twitterLogin_getTwitterLoginUrl();?>"
        onclick="<?php echo twitterLogin_getTwitterLoginUrl_popupOnClick(); ?>">Login with Twitter</a><br/><br/>
      <?php endif ?>

      <a href="https://vascularregistry.gr/registry/admin.php?menu=forgotPassword">Forgot your password?</a> 

    </td>
   </tr>
  </table>
  </form>
<?php endif ?>
<!-- /USER LOGIN FORM -->

I will try to play a bit with it later on and let you know how it is getting on.

Thank you again for your great assistance

Regards

Andreas

By daniel - May 29, 2020

Hi Andreas,

A quick look makes me think that this line could be an issue:

if (!getPrefixedCookie('lastUrl')) { setPrefixedCookie('lastUrl', @$_SERVER['HTTP_REFERER'] ); }

You can try commenting it out and see if that works. This line is responsible for redirecting a user back to their previous page after logging in; without it, they should instead be directed to the "WEBSITE_LOGIN_POST_LOGIN_URL" setting in websiteMembership.php

Let me know how that works, or if you find anything else.

Thanks!

Daniel
Technical Lead
interactivetools.com

By andreasml - May 30, 2020

Hi Daniel,

It worked!! You cannot imagine how long I tried in vain to find a solution. You are really great. You and your company give meaning to the word professionalism. I wish I would be such good in my job as you are in yours.

I am really glad to have met Interactivetools.com and to have been working with you. 

My best regards,

Andreas