Error with Website Membership plugin

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

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 daniel - May 28, 2020 - edited: May 28, 2020

Hi Andreas,

The second part should go at the top of any WordPress page where you want to use the CMSB functions. It will display an error if the viewer library doesn't load properly for any reason; it's technically optional, but useful to have.

Cheers,

Daniel
Technical Lead
interactivetools.com

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