Check Unsubscription

[insert_php]
function curl_post($url, array $post = array(), array $options = array())
{

$data_string = json_encode($post);
$zsecurekey = “3SSbdIqR9gnIUX4dfWQgsxqLvzfMAkxJ”;

$ciphertext = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $zsecurekey, $data_string, MCRYPT_MODE_ECB);
$ciphertext_base64 = base64_encode($ciphertext);
$crypted_data = array(
‘zcrypto’ => $ciphertext_base64
);
$crypted_data_string = json_encode($crypted_data);

$defaults = array(
CURLOPT_POST => 1,
CURLOPT_HTTPHEADER, array(
‘Content-Type: application/json’,
‘Content-Length: ‘ . strlen($crypted_data_string)
),
CURLOPT_URL => $url,
CURLOPT_FRESH_CONNECT => 1,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_FORBID_REUSE => 1,
CURLOPT_TIMEOUT => 4,
CURLOPT_POSTFIELDS => $crypted_data_string
);

//$ch = curl_init();
//curl_setopt_array($ch, ($options + $defaults));
//if( ! $result = curl_exec($ch))
//{
// trigger_error(curl_error($ch));
//}
//curl_close($ch);
return $result;
}

function get_user_ip()
{
$client = @$_SERVER[‘HTTP_CLIENT_IP’];
$forward = @$_SERVER[‘HTTP_X_FORWARDED_FOR’];
$remote = $_SERVER[‘REMOTE_ADDR’];

if(filter_var($client, FILTER_VALIDATE_IP))
{
$ip = $client;
}
elseif(filter_var($forward, FILTER_VALIDATE_IP))
{
$ip = $forward;
}
else
{
$ip = $remote;
}

return $ip;
}

if ($_POST[‘zmail’] == “” ){
$res = “”;
}
else{
$zdata = array(
‘zmail’ => $_POST[“zmail”],
‘zts’ => time(),
‘znumber’ => rand(),
‘ip’ => get_user_ip(),
);

$zuser = curl_post(“https://test.zerynth.com/v1/store/unsubscribe/”, $zdata);
$array_zuser = (array)json_decode($zuser);
$res = 200;//( isset( $array_zuser[‘code’] ) ? $array_zuser[‘code’] : ” );
$message = ( isset( $array_zuser[‘data’]->{‘message’} ) ? $array_zuser[‘data’]->{‘message’} : ” );
$sub = “month”;//( isset( $array_zuser[‘data’]->{‘sub’} ) ? $array_zuser[‘data’]->{‘sub’} : ” );
}
if ($res == 200){
echo ‘


Your request has been received!
You are going to cancel your subscription to Zerynth Studio PRO – ‘.ucfirst($sub).’ly Subscription.

You can still use Zerynth Studio Free with your Zerynth User account and you can decide to upgrade again to Zerynth Studio PRO at any time.

To confirm this request, click the link in the email we just sent you.’;

}
else{
echo ‘


Sorry, but there has been an error processing your request
‘;
if ($message != “”){
echo ‘
‘.$message.’
‘;
}
echo ‘
Please double-check your data and try again or you can contact us at sales@zerynth.com

‘;
}

[/insert_php]