0

Well for my site i want my users to be on a monthly membership. so once they buy the membership they will have it for 31 days. how do i make it so when the 31 days run out they lose there membership. also I want to make the monthly membership Recurring. I guess ill just show you guys my ipn for paypal.

 <?php
 include("session1.php");
 ini_set('log_errors', true);
 ini_set('error_log', dirname(__FILE__).'/ipn_errors.log');

include('ipnlistener.php'); 
$listener = new IpnListener();

$listener->use_sandbox = true;
try {
$listener->requirePostMethod();
$verified = $listener->processIpn();
 } catch (Exception $e) {
 error_log($e->getMessage());
 exit(0);
 }

 if ($verified) {
 $errmsg = '';  
 if ($_POST['payment_status'] != 'Completed') { 
    exit(0); 
 }
 if ($_POST['mc_currency'] != 'USD') {
    $errmsg .= "'mc_currency' does not match: ";
    $errmsg .= $_POST['mc_currency']."\n";
 }
  else
 require("include/config.php");
 $mailer = "email@email.com";
  $item_name = $_POST['item_name'];
  $item_number = $_POST['item_number'];
 $payment_status = $_POST['payment_status'];
 $payment_amount = $_POST['mc_gross'];
 $payment_currency = $_POST['mc_currency'];
 $txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$email = $_POST['payer_email'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$custom = $_POST["custom"];
$userid = $custom;

mysql_query("UPDATE users SET plan='$item_name', memberstatus='member', subdays='31' WHERE username='$userid'");
$sql = "INSERT INTO orders VALUES 
(NULL, '$userid', '$receiver_email', '$item_name', '$payment_amount')";

    echo "Payment accpeted. Redirecting ";
    if (!mysql_query($sql)) {
        error_log(mysql_error());
        exit(0);
    }
}
?>
4

1 回答 1

0

您可以使用数据库轻松完成此操作。将一个字段添加到您的members数据库表中,名为last_renewed. 此字段将包含timestamp成员最后一次续订帐户的时间。

在您的 php 文件中,将当前时间last_renewed与相差 31 天的值进行比较。

例如(使用 unix 时间戳)

$period = 31*24*60*60; //31 days in seconds.
if(time() - $member['last_renewed'] > $period)
{
  echo "You'll have to renew your account";
}
else
{
   //He's ok.
}

编辑:您的更新代码:

$time = time(); //Current unix timestamp
mysql_query("UPDATE users SET plan='$item_name', memberstatus='member', subdays='$time' WHERE username='$userid'");
于 2012-08-25T09:11:53.673 回答