Jump to content

Paid Subscription


Bman900

Recommended Posts

So lets say I want to make a site where people can buy memberships for 30 days or for a whole year. I have a user system but I have no clue on how to do this. I was thinking after the payment is made I can enter a code in the database that get checked when the user is logged in. The problem that I am running into is how to I change that code in the database after 30 days or 12 months after they signed up so they wont have a subscription any more?

Link to comment
Share on other sites

Just store the date they paid up to,

so

time()+(30*24*60*60)

for 30days

 

Or the date they paid, and the type of account (30 days / 1 year / etc)

 

yah or to save the cpu power of processing all those multiplication cpu instructions

 

just type in google 30 days to seconds

 

which gives you 2592000

 

time()+2592000;  = 30 days

Link to comment
Share on other sites

You don't need to drop any values, if the paid for a subscription to until 06/24/2010 then you just need to compare to the current date

ie

SELECT * FROM payements WHERE paidto >= CURDATE();

 

 

Personally I find it quicker to do (30*24*60*60), its quicker to debug and update vs microseconds to process!

 

infact i just ran a benchmark, 5000 iterations

 

it seams sometimes mine is quicker!, which is kinda unexpected!

0.00064196524620056 //pkedpker

0.00064111461639404 //mine

 

0.00065427861213684 //pkedpker

0.00064351334571838 //mine

 

0.00067055644989014  //pkedpker

0.00067531914710999  //mine

 

0.00056252417564392 //pkedpker

0.0005777334690094 //mine

 

0.00063268013000488 //pkedpker
0.00069262042045593 //mine

Link to comment
Share on other sites

haha like a few microseconds in the cpu really matter.. but yah i guess its nicer doing it your way of course.. .. maybe even make a static constant with that value and called it THIRTY_DAYS

 

but then accessing the constant may be slower then typing the magic number lol so either way its sucks

Link to comment
Share on other sites

You don't need to drop any values, if the paid for a subscription to until 06/24/2010 then you just need to compare to the current date

ie

SELECT * FROM payements WHERE paidto >= CURDATE();

 

 

Correct me if am wrong. I will put that in an query and run it. Then it should return a value if there is something in there. If not that obviously they don't have a subscription or it was expired. So after the query I  can run an if (something got returend) { do thid} else { you don't have a subscription}

Link to comment
Share on other sites

Correct me if am wrong. I will put that in an query and run it. Then it should return a value if there is something in there. If not that obviously they don't have a subscription or it was expired. So after the query I  can run an if (something got returend) { do thid} else { you don't have a subscription}

 

if the paidto is set in the future (from when they paid) (ie they have paid up to that date)

then anyone found has a valid membership

 

 

maybe even make a static constant with that value and called it THIRTY_DAYS

wouldn't that use a few extra bytes of memory!! LOL

 

Its all down to personal preference, I guess! but I try to keep in mind what makes upgrades quicker and safer

Link to comment
Share on other sites

It'll give everyone who still has a subscription not 1 person.. so I have no idea how that will help you.. too much you can either check every name then while the loop is going or you can just check right away in the query  WHERE name='username' or  id='userId' AND paidto >= CUTDATE();

 

yah you can do a if statement with the results from  mysql_num_rows()

 

 

@MadTechie: lol yah its all personal preference but not really that big of a deal to remember since you know NOW() always returns seconds and anything that big has to be alot!

P.S> you think you could look at the TIMESTAMP question of mines I still don't know which function is better and since you are good at benchmarking all I care about is execution speed

Link to comment
Share on other sites

/*
###Check user is registered/logged in
###Process Payment
*/
// If payment valid
// Subscription length stored in $subscriptionLength
if ( $subscriptionLength == "30 days" )
{
   $subscriptionLength = time() + (( 3600 * 24 ) * 30);
}
elseif ($subscriptionLength == "1 year" )
{
   $subscriptionLength = time() + (( 3600 * 24 ) * 365);
}

   $query = "UPDATE userTable SET subscription = " . $subscriptionLegth . " WHERE userField = '" . mysql_real_escape_string($userSession) . "' LIMIT 1";
   $result = mysql_query($query); // or handle error

   if ($result)
   {
      Header("Location: subscriptionSuccess.htm");
   }
   else
   {
      Header("Location: subscriptionFail.htm");
   }

 // else give error

 

/*
### Check subscription valid
*/
$query = "SELECT subscription FROM userTable WHERE userField = '" . mysql_real_escape_string($userSession) . "' LIMIT 1";
$result = mysql_query($query); // or handle error

   $row = mysql_fetch_row($result);

   $subscriptionLeft = $row[0] - time();

   if ($subscriptionLeft <= 0)
   {
      Header("Location: expired.php?act=Renew");
   }

/*
###Include this file at top of each page where subscription is required after session_start() and db connection
*/

 

Could do something like that? 

Link to comment
Share on other sites

Yah andy thats nice but it always strikes me odd.. how people use LIMIT 1.. after that wouldn't it give 1 result either way?.. not like your using a LIKE command which gets things that have similar names.. like  if you do a query for 'And' it will return  Andy, Andrew. etc..

 

other then that whats the point? of using LIMIT 1  (correct me if im wrong i'm still a noobie at php only been using it for a week now lol)

Link to comment
Share on other sites

Because the registered username/id should be unique, in effect, the query SHOULD only select one field; so if there is an error in the registration script (or something) and somehow two entries of the same name have "somehow" got in there, it wont update or select the user field twice and lose subscription money. It would probably never happen but, who knows...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.