TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 10-13-2008, 08:11 PM   #1 (permalink)
The Acquainted
 
KingOfTheSouth's Avatar
 
Join Date: Oct 2008
Location: Cincinnati
Posts: 151
Thanks: 14
KingOfTheSouth is on a distinguished road
Default Stuck with timestamps

I own a online game and have subscriptions to the game and I am trying to get the subscriptions last only last 30 days which I am having trouble with..

php Code:
if($user["status"] == 3)
        {
            $sup = "No, <a href='credits.php?action=purchase'>Want to be one?</a>";
        }else{
            $sup = "Yes";
        }

if($user["substatus"] == 0)
        {
            $sub = "No";
        }
        elseif($user["substatus"] == 1)
        {
            $sub = "Level One (+5 turns / +500hold)";
        }
        elseif($user["substatus"] == 2)
        {
            $sub = "Level Two (+10 turns / +1,000hold)";
        }
                elseif($user["substatus"] == 3)
        {
            $sub = "Level Two (+15 turns / +1,500hold)";
        }


if($user["substatus"] == 1){$length = 1199145600;}
if($user["substatus"] == 2){$length = 1199145600;}
if($user["substatus"] == 3){$length = 1199145600;}

$expire = $subtime["datebought"]+$length;


Here is the code I just cannot make them only last 30 days. If you can help me please I will appreciate it

Last edited by Wildhoney : 10-13-2008 at 09:04 PM.
KingOfTheSouth is offline  
Reply With Quote
Old 10-13-2008, 08:17 PM   #2 (permalink)
The Frequenter
 
ReSpawN's Avatar
 
Join Date: Nov 2007
Location: Netherlands
Posts: 460
Thanks: 49
ReSpawN is on a distinguished road
Default

First off, you should formulate your variables and so forth.

The most wise thing to do, is to, when people register, post a timestamp with just the time() function or
PHP Code:
list( $microTime$timeStamp ) = explode" "microtime() );
$registerDate = ( $microTime $timeStamp );

// Or just do this, which is more general but easy. microtime() is only used for timestamp and so forth (query time etc.)
$registerDate time(); 
That returns the date which can be transformed like so;
PHP Code:
print( date'H:i:s d-m-Y'$registerDate ) ); 
This returns it in every format you want.

If this is not what you mean, please formulate your post a bit more accurate and tell me what your plan is.
__________________
"Life is a bitch, take that bitch on a ride"
Send a message via MSN to ReSpawN
ReSpawN is offline  
Reply With Quote
The Following User Says Thank You to ReSpawN For This Useful Post:
KingOfTheSouth (10-13-2008)
Old 10-13-2008, 08:19 PM   #3 (permalink)
The Acquainted
 
KingOfTheSouth's Avatar
 
Join Date: Oct 2008
Location: Cincinnati
Posts: 151
Thanks: 14
KingOfTheSouth is on a distinguished road
Default

Well I am not that good at coding I taught myself everything I know but I will give it a shot..
KingOfTheSouth is offline  
Reply With Quote
Old 10-13-2008, 09:11 PM   #4 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

It is quite simple, you'll just have to find a place in your code to insert it. I hope it helps you!

php Code:
function has_subscription_expired($iTimestamp, $iDays = 30)
{
    $iNadir = strtotime(sprintf('-%d days', $iDays));
   
    if ($iTimestamp < $iNadir)
    {
        return true;
    }
   
    return false;
}

var_dump(has_subscription_expired(strtotime('-35 days'))); // true
var_dump(has_subscription_expired(strtotime('-30 days'))); // false
var_dump(has_subscription_expired(strtotime('-25 days'))); // false
 
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 10-13-2008, 10:29 PM   #5 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Could you please explain this for me please:
PHP Code:
strtotime(sprintf('-%d days'$iDays)) 
I know how sprintf works. I just don't understand why you write "days" in there??
And same thing when you use the function, you write
PHP Code:
(strtotime('-25 days')) 
Why "days" there?? :S And why a MINUS ?? :O
__________________
Tanax is offline  
Reply With Quote
Old 10-13-2008, 11:11 PM   #6 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

You're deducting 25 days off the current date with that command. You can do plus and minuses. As well as days, years, seconds, months, et cetera...
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
The Following 2 Users Say Thank You to Wildhoney For This Useful Post:
KingOfTheSouth (10-14-2008), Tanax (10-14-2008)
Old 10-14-2008, 12:50 AM   #7 (permalink)
The Acquainted
 
KingOfTheSouth's Avatar
 
Join Date: Oct 2008
Location: Cincinnati
Posts: 151
Thanks: 14
KingOfTheSouth is on a distinguished road
Default

I get what you are saying. I just really needed help with that because my partner is out of the country and he does all of the coding that is what he does for a living. But thanks alot
KingOfTheSouth is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 06:07 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design