PHP: // check.php A simple way to use ajax with amember // returns 1 if user is logged in and subscription is valid // returns 0 if user is not currently subscribed or has a valid subscription session_start(); //array of product id's allowed to access content //passed as array in post $product_id = $_POST['pid']; //http://manual.amember.com/AMember_Session_Variables //array_intersect($product_id, $_SESSION['_amember_product_ids']) //This variable (array) contains list of Product ID# that current customer is subscribed to (and subscription is paid and non-expired). //isset($_SESSION['_amember_user']) //This checks to see if user is logged in if (array_intersect($product_id, $_SESSION['_amember_product_ids']) && isset($_SESSION['_amember_user'])){ echo 1; } else { echo 0; } Code: <html> <head> <title>AJAX Test</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script> <body> <form action="/" id="form"> <input type="submit" value="Ajax" /> </form> <script> var id = ["1", "2", "3"]; $("#form").submit(function(event) { /* stop form from submitting normally */ event.preventDefault(); $.post("check.php",{ pid : id },function( data ) { alert("Data Returned: " + data); } ); }); </script> </body> </html> Two files. Save the php code as check.php. Save the html as whatever. Change the id array to your product id's. Make sure jquery is properly linked. Logout of your site. Go to html file, hit button. Login to your site. Hit button. <sucess> Feel free to expand on this. I built a log-in check and used the php here to also check for the required product. If its good my app does good stuff. If the user doesn't have the correct product, my app tells them where to go to get the good stuff. Doing my part to move aMember past 1999 !! Edit: Yes, you need to do proper things to make sure there its a post and variables aren't malicious. Kept this simple.
Just wanted to bump this thread, see if anyone has tried/used this, and if anyone has any plans on expanding it? We are trying with aMember 4 this week.
aMember Pro login form is already AJAXified. I will write instructions how to insert it to any HTML page on website. It is more complex with signup form, I'd not recommend to do that. Customize the aMember layout instead.
Yeah, this is for Amember 3 - so I reccomend everyone upgrade to Amember 4. Seems amember will have an ajax login, which is very cool, and I look forward to integrating it as the login for our web app. I will post here for those interested with a link the Amember 4 forums. Great work Alex !!
Hi Alex, I know this is an older thread, but I was looking for the instructions on how to insert an AJAX driven login form into any HTML page. Thanks, [edit], can you also tell me how I can redirect to a page on a FAILED LOGIN attempt? I know how to do a redirect on success , but need to know what to change to redirect on failed attempt. The goal being to redirect to a FAQ page or some help for those who fail login. Thanks.