¿Cómo codificar una membresía cronometrada?

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);
    }
}
?>

preguntado el 25 de agosto de 12 a las 10:08

Y por favor, no uses mysql_* funciones para el nuevo código. Ya no se mantienen y la comunidad ha comenzado la proceso de desaprobación. Consulte las caja roja? En su lugar, debería aprender sobre declaraciones preparadas y usa ya sea PDO or MySQLi. Si no puedes decidir este artículo ayudará a elegir. Si te importa aprender, aquí hay un buen tutorial de PDO. -

1 Respuestas

You can do it easily with Database. Add a field to your members DB Table , named last_renewed. This field will contain the timestamp of the last time the member renewed his account.

In your php file , compare the current time to the last_renewed value with a difference of 31 days.

For instance (using unix timestamp)

$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.
}

EDIT: Your update code:

$time = time(); //Current unix timestamp
mysql_query("UPDATE users SET plan='$item_name', memberstatus='member', subdays='$time' WHERE username='$userid'");

Respondido 25 ago 12, 10:08

how would i add the timestamp in to the sql? mysql_query("UPDATE users SET plan='$item_name', memberstatus='member', subdays='UNIX_TIMESTAMP()' WHERE username='$userid'"); would it be like that? - user1610205

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.