aMember membership software integration

aMember is the leading membership management software. Integrating the software into Textpattern turns out to be quite easy – you can see the results of an integration on the Pro Tennis Jobs site. Here’s how you do it:

  1. Install aMember with a folder name that does not match a TXP section
  2. Add session_start() to the top of your TXP page if you wish to track variables
  3. Use a PHP file to check if a user is logged in and a current member
  4. Use two TXP forms to show content based on membership status

Once you have installed aMember, you are good to go. In our case, we installed aMember in a folder called “subscribers”.

Add session_start() to your page

<txp:php> session_start(); </txp:php>

This step needs to be taken IF you want to track aMember variables on your site. In the case of Pro Tennis Jobs, we needed to track subscribers in the Tennis Jobs categories, as only paid up subscribers may view the Tennis Job contact details (see the “you are not logged in” – if a subscriber is logged in he/she will see a welcome message along with the relevant contact details).

Track your members in your page

<txp:if_individual_article>
<txp:if_section name="tennis-jobs">
<txp:php>
include "/users/home/myname/domains/yoururl.com/scripts/if_logged_in.php";
</txp:php>
<txp:article form="job_single" limit="1" />
</txp:if_section>
</txp:if_individual_article>

You will need to adjust the include path to your PHP script.

if_logged_in.php file

<?php
//function for connecting to the database
function dbConnect($db="") {
    $dbhost = "localhost";
    $dbuser = "username";
    $dbpass = "password";
    $dbcnx = @mysql_connect($dbhost, $dbuser, $dbpass)
        or die("The site database appears to be down.");
    if ($db!="" and !@mysql_select_db($db))
        die("The site database is unavailable.");
    return $dbcnx;
}
//Connect to DB
dbConnect("my_db_name");
//AMember variables - check what product user is subscriber to (paid and non-expired)
if(array_intersect($_SESSION['_amember_product_ids'], array(1,2,3,4,5))) { 
//Connect to DB and select TXP form contents
$query = "SELECT Form FROM txp_form WHERE name = 'logged_in_yes'";
$result = mysql_query($query) or die ('Failed to execute query');
$logged_in_yes = mysql_result($result, 0);          
echo $logged_in_yes;   
//if the user not logged in, display login form
  }  else  {
$query = "SELECT Form FROM txp_form WHERE name = 'logged_in_no'";
$result = mysql_query($query) or die ('Failed to execute query');
$logged_in_no = mysql_result($result, 0);
echo $logged_in_no;   
  } 
?>

The if_logged_in.php file connects to the database and checks if a user is a current paid up subscriber, and to which product the user is subscribed to.

Use TXP forms to display content

<div class="logged-in">
<h2><txp:php> print "Welcome, " . $_SESSION['_amember_user']['name_f'] . " " . $_SESSION['_amember_user']['name_l']; </txp:php></h2>
<h3>Contact details for this Tennis Job:</h3>
<p>
<txp:if_custom_field name="Contact"><span class="fields">Contact: </span> <txp:custom_field name="Contact" /><br /></txp:if_custom_field>
<txp:if_custom_field name="Email"><span class="fields">Email: </span><txp:custom_field name="Email" /><br /></txp:if_custom_field>
<txp:if_custom_field name="Telephone"><span class="fields">Telephone: </span><txp:custom_field name="Telephone" /><br /></txp:if_custom_field>
<txp:if_custom_field name="Fax"><span class="fields">Fax: </span><txp:custom_field name="Fax" /><br /></txp:if_custom_field>
<txp:if_custom_field name="City"><span class="fields">City: </span><txp:custom_field name="City" /><br /></txp:if_custom_field>
<txp:if_custom_field name="Address"><span class="fields">Address: </span><txp:custom_field name="Address" /><br /></txp:if_custom_field>
<txp:if_custom_field name="URL"><span class="fields">URL: </span><txp:custom_field name="URL" /><br /></txp:if_custom_field>
</p>
</div>

The above form is called logged_in_yes and called from the PHP script. The form displays a welcome message for current, paid up subscribers, along with the tennis job contact details from the Pro Tennis Jobs site.

If not a current subscriber, display something else

<div class="logged-in">
<h2>You are NOT logged in</h2>
<p>Only current subscribers may see the contact details for this Tennis Job - Subscribers <a href="/subscribers/member.php">login here</a>, or use the login box on the right of the page.</p>
<p>Not a subscriber yet? <a href="/subscribers/signup.php">Subscribe now</a> to the Tennis Jobs database</p>
</div>

The above form, called logged_in_no (also called from the PHP script) displays a message for non-subscribers.

Some further information from the aMember manual:

aMember Manual

comments powered by Disqus