MMv4 KB
 
Create a Multi-Level RMV Login
  Last Edited - 01/8/2014 9:43am PST
  Category Path - Shopping Cart Software Components > Administration Area > Modules > Subscription Products > Memberships & Remote Member Validation (RMV) System
 
Modular Merchant's Remote Membership Validation (RMV) system allows you to create a members-only area to your website, where only those customers of a certain product or products may log in to it.

It's a great tool that lets your website communicate with the shopping cart software in order to confirm that the customer trying to log in has a valid subscription to the required products in your store.

The basic RMV tutorial demonstrates how to add a login that requires a subscription to a single product to a website.

But what about if you're selling multiple products (such as Bronze, Silver and Gold membership levels), and you want to have a single login page which redirects the customer to the appropriate Bronze, Silver or Gold section of your website after they log in, based on which one of those products they are subscribed to?

This tutorial will demonstrate how to create such a "multi-level" RMV login.

prerequisites
This tutorial assumes that the reader is already familiar with the shopping cart's RMV API, and is comfortable working with HTML and PHP source code.

If not, it's recommended that you start with the basic RMV tutorial in order to learn the basic concepts of how the remote subscriber login system works.

First, let's start with a sample of some HTML and PHP code for a login page on a website. This login will require the user to have a subscription to either product SID 111, 222 or 333 in my store. A subscription to any one of those products will allow them to log in.

code
<?php
session_start
();

$store_url 'http://www.MyShoppingCartURL.com';
$api_key '9c1bc31d15sr23a22c9ba51d621a7b2fd';
$product_ids '111,222,333';
$any_all 'any';
$subscription_vs_order 'subscription';
$results_format 'xml';

include(
'mm_membership_validator.php');

$_SESSION['is_membership_valid'] = $is_membership_valid;

if(
$_SESSION['is_membership_valid'] == 'Y') {
   
session_write_close();
   
header('location: my_content_webpage.php');
   exit();
}
?>

<form action="my_login_webpage.php" method="post" name="login_form">
   Email: <input name="email" type="text" value="" />
   Password: <input name="password" type="password" value="" />
   <input name="submit" type="submit" value="Log In" />
</form>


The key to creating a multi-level RML login is the presence of the $results_format = 'xml'; setting in the sample code above. That setting will change the response that the shopping cart reports back from a simply "Y/N" response to a block of XML data containing information about the customer's account.

xml response sample
This article will focus on just one section of the block of XML data returned by the shopping cart. For an in-depth review of all the content contained in the XML data, refer to the Working With RMV XML Data article.

The subscription_data section of the XML data will contain a list of all of the products that the customer is subscribed to. For example, it may look something like this:

code
<subscription_data>
   <subscription_item>
       <product_sid>222</product_sid>
       <product_name>Silver+Level+Membership</product_name>
       <bill_date>1222122161</bill_date>
   </subscription_item>
   <subscription_item>
       <product_sid>456</product_sid>
       <product_name>Some+Other+Product+In+Their+Subscription</product_name>
       <bill_date>1113174152</bill_date>
   </subscription_item>
</subscription_data>


Now that a list of all of the products in the customer's subscription is available, the next step is to loop through it to record which of the required products they are subscribed to. Here's an example of how the list of subscription_items could be looped through:

code

<?php
// Change the XML data string into a PHP object.
$rmv_object simplexml_load_string($rmv_results);

// Create a variable to help us loop through the array of subscription_items.
$i 0;

// Create an array to store the list of products that the customer is subscribed to.
$sids = array();

// Loop through the list of subscription_items, recording the
// SID number of each product in the subscription in the $subscription_item array.
while($i count($rmv_object->subscription_data->subscription_item)) {
    
$sids[] = (int)$rmv_object->subscription_data->subscription_item[$i]->product_sid;
    
$i++;
// end while
?>


The list of product SID numbers that the customer is subscribed to is now stored in the $sids array. The original login code can now be updated to reference this array, and redirect to either the Bronze, Silver or Gold membership area accordingly, depending on which product they're subscribed to.

Here's an example of a revised version of the original login code above:

code
<?php
session_start
();

$store_url 'http://www.MyShoppingCartURL.com';
$api_key '9c1bc31d15sr23a22c9ba51d621a7b2fd';
$product_ids '111,222,333';
$any_all 'any';
$subscription_vs_order 'subscription';
$results_format 'xml';

include(
'mm_membership_validator.php');

$_SESSION['is_membership_valid'] = $is_membership_valid;

$rmv_object simplexml_load_string($rmv_results);

$i 0;
$sids = array();
while(
$i count($rmv_object->subscription_data->subscription_item)) {
    
$sids[] = (int)$rmv_object->subscription_data->subscription_item[$i]->product_sid;
    
$i++;
}

if(
in_array('111'$sids)) {
   
session_write_close();
   
header('location: bronze_webpage.php');
   exit();
} elseif(
in_array('222'$sids)) {
   
session_write_close();
   
header('location: silver_webpage.php');
   exit();
} elseif(
in_array('333'$sids)) {
   
session_write_close();
   
header('location: gold_webpage.php');
   exit();
}
?>

<form action="my_login_webpage.php" method="post" name="login_form">
   Email: <input name="email" type="text" value="" />
   Password: <input name="password" type="password" value="" />
   <input name="submit" type="submit" value="Log In" />
</form>


Using the approach described above, it would be possible to create a login page on your own website that connects to your store, confirms that the user is subscribed to one of the required products, and then redirects them to the appropriate page on your website, depending on which specific product they're subscribed to.
Powered by ModularKB