Hello to Everyone: In Amember 3.x i use the following code to insert and subscribe users to ThirdParty Script when create a new suscriptions: PHP: function postToRemoteURL($URL, $post_parameters, $HTTPRequestType = 'POST', $HTTPAuth = false, $HTTPAuthUsername = '', $HTTPAuthPassword = '', $ConnectTimeOutSeconds = 60, $ReturnHeaders = false){ $PostParameters = implode('&', $post_parameters); $CurlHandler = curl_init(); curl_setopt($CurlHandler, CURLOPT_URL, $URL); if ($HTTPRequestType == 'GET') { curl_setopt($CurlHandler, CURLOPT_HTTPGET, true); } elseif ($HTTPRequestType == 'PUT') { curl_setopt($CurlHandler, CURLOPT_PUT, true); } elseif ($HTTPRequestType == 'DELETE') { curl_setopt($CurlHandler, CURLOPT_CUSTOMREQUEST, 'DELETE'); } else { curl_setopt($CurlHandler, CURLOPT_POST, true); curl_setopt($CurlHandler, CURLOPT_POSTFIELDS, $PostParameters); } curl_setopt($CurlHandler, CURLOPT_RETURNTRANSFER, 1); curl_setopt($CurlHandler, CURLOPT_CONNECTTIMEOUT, $ConnectTimeOutSeconds); curl_setopt($CurlHandler, CURLOPT_TIMEOUT, $ConnectTimeOutSeconds); curl_setopt($CurlHandler, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3'); if ((ini_get('safe_mode') != false) && (ini_get('open_basedir') != false)) { curl_setopt($CurlHandler, CURLOPT_FOLLOWLOCATION, true); } if ($ReturnHeaders == true) { curl_setopt($CurlHandler, CURLOPT_HEADER, true); } else { curl_setopt($CurlHandler, CURLOPT_HEADER, false); } if ($HTTPAuth == true) { curl_setopt($CurlHandler, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($CurlHandler, CURLOPT_USERPWD, $HTTPAuthUsername . ':' . $HTTPAuthPassword); } $RemoteContent = curl_exec($CurlHandler); if (curl_error($CurlHandler) != '') { return array(false, curl_error($CurlHandler)); } curl_close($CurlHandler); return array(true, $RemoteContent);} function subscriberSubscribe($member_id, $product_id, $member){ $customeremail = strtolower($member['email']); $customername_f = ucfirst(strtolower($member['name_f'])); $customername_l = ucfirst(strtolower($member['name_l'])); $post_parameters = array(); $post_parameters[] = "Command=Subscriber.Subscribe"; $post_parameters[] = "ResponseFormat=JSON"; $post_parameters[] = "ListID=702"; $post_parameters[] = "EmailAddress=" . $customeremail; $post_parameters[] = "IPAddress=" . $_SERVER['REMOTE_ADDR']; $post_parameters[] = "CustomField1=" . $customername_f; $post_parameters[] = "CustomField2=" . $customername_l; $response = postToRemoteURL("http://www.mydomain.com/c/api.php?", $post_parameters); if (empty($response[0])) { return false; } else { return json_decode($response[1]); }} function userCreate($member_id, $product_id, $member){ $data = unserialize($data); $customer_email = strtolower($member['email']); $customer_name_f = ucfirst(strtolower($member['name_f'])); $customer_name_l = ucfirst(strtolower($member['name_l'])); $customer_name_pass = md5($member['pass']); $customer_name_login = $member['login']; $customer_web = strtolower($member['data']['web']); if ($product_id == '12' or $product_id == '20' or $product_id == '21' or $product_id == '22') { $$post_parameters = array(); $post_parameters[] = "Command=User.Create"; $post_parameters[] = "ResponseFormat=JSON"; $post_parameters[] = "Username=" . $customer_name_login; $post_parameters[] = "Password=" . $customer_name_pass; $post_parameters[] = "EmailAddress=" . $customer_email; $post_parameters[] = "FirstName=" . $customer_name_f; $post_parameters[] = "LastName=" . $customer_name_l; $post_parameters[] = "Language=EN"; $post_parameters[] = "IPAddress=" . $_SERVER['REMOTE_ADDR']; $post_parameters[] = "TimeZone=(GMT-05:00) Bogota"; $post_parameters[] = "RelUserGroupID=15"; $post_parameters[] = "Website=" . $customer_web; $response = postToRemoteURL("http://www.mydomain.com/c/api2.php?", $post_parameters); } else if ($product_id == '13' or $product_id == '23' or $product_id == '24' or $product_id == '25') { $$post_parameters = array(); $post_parameters[] = "Command=User.Create"; $post_parameters[] = "ResponseFormat=JSON"; $post_parameters[] = "Username=" . $customer_name_login; $post_parameters[] = "Password=" . $customer_name_pass; $post_parameters[] = "EmailAddress=" . $customer_email; $post_parameters[] = "FirstName=" . $customer_name_f; $post_parameters[] = "LastName=" . $customer_name_l; $post_parameters[] = "Language=EN"; $post_parameters[] = "IPAddress=" . $_SERVER['REMOTE_ADDR']; $post_parameters[] = "TimeZone=(GMT-05:00) Bogota"; $post_parameters[] = "RelUserGroupID=16"; $post_parameters[] = "Website=" . $customer_web; $response = postToRemoteURL("http://www.mydomain.com/c/api2.php?", $post_parameters); } if (empty($response[0])) { return false; } else { return json_decode($response[1]); } } setup_plugin_hook("subscription_added", "subscriberSubscribe"); setup_plugin_hook("subscription_added", "userCreate"); Maybe can help me to change this code works with Amember 4 Many Thanks in Advance
Here is example of the code for aMember v4. (it should be placed to /amember/application/configs/site.php : ) PHP: <? Am_Di::getInstance()->hook->add('subscriptionAdded', 'subscriptionAdded'); function subscriptionAdded(Am_Event $event){ $user = $event->getUser(); $product = $event->getProduct(); /// Your code which make requests go there: /// You can check $user and $product classes defenition in /amember/application/default/models/User.php and Product.php }?>
Hi Alexander Many Thanks in Advance for your Help, i am not a programmer, i´m trying with the following code but is not working: Fatal error: Cannot use object of type User as array in PHP: Am_Di::getInstance()->hook->add('subscriptionAdded', 'subscriberSubscribe'); PHP: function subscriberSubscribe(Am_Event $event){ $user = $event->getUser(); $product = $event->getProduct(); $customeremail = strtolower($user['email']); $customername_f = ucfirst(strtolower($user['name_f'])); $customername_l = ucfirst(strtolower($user['name_l'])); $post_parameters = array(); $post_parameters[] = "Command=Subscriber.Subscribe"; $post_parameters[] = "ResponseFormat=JSON"; $post_parameters[] = "ListID=702"; $post_parameters[] = "EmailAddress=" . $customeremail; $post_parameters[] = "IPAddress=" . $_SERVER['REMOTE_ADDR']; $post_parameters[] = "CustomField1=" . $customername_f; $post_parameters[] = "CustomField2=" . $customername_l; $response = postToRemoteURL("http://www.domain.com/c/api.php?", $post_parameters); if (empty($response[0])) { return false; } else { return json_decode($response[1]); } } Please Help
Error is correct, you try to use $user object as an array. If you want to get access to user variables use this instead: PHP: $customeremail = strtolower($user->email); Check /amember/application/default/models/User.php for more info.
Hi Alexander Many Thanks for your invaluable help.....now my script Works! I have a little question: I use PHP: $Password = $user->pass to get password but in other aplication can´t login, is there some way to get the pass in plaintext format or how i can send the correct password to other aplication? Is md5 encrypted? Thanks in Advance
Jose, aMember do not store plain text password anymore. Is this absolutely necessary to send palin text password? Can other application be adapted to work with PHPass http://www.openwall.com/phpass/ (this is password format being used in aMember)? If this is not possible to use encrypted passwords, you have to create plugin then (and not to use hooks in site.php) : 1. Remove everything that you have added to site.php 2. Create /amember/application/default/plugins/protect/yourpluginname.php with this code: PHP: <?php class Am_Protect_ extends Am_Protect_Abstract{ public function getPasswordFormat() { return SavedPassTable::PASSWORD_PLAIN; } public function onSubscriptionAdded(Am_Event $event){ $user = $event->getUser(); $product = $event->getProduct(); /// Your code here; $pass = $this->getDi()->savedPassTable->findSaved($user, SavedPassTable::PASSWORD_PLAIN); }}?> 3. Enable yourpluginname in aMember CP -> Setup -> Plugins
Hi Alexander Many Thanks: Other Script use password in MD5 format..... Can i get the password in MD5 format in site.php without use a plugin? Please give a example how to get the password in MD5 format in site .php Thanks in Advance
Hi Alexander: When i create a manual suscription to some user...plugin not work... Thanks in Advance
Hi: Other Script use password in MD5 format..... Can i get the password in MD5 format in site.php without use a plugin?Please give a example how to get the password in MD5 format in site .phpWhen i create a manual suscription to some user...plugin not work.. Please help Thanks