Solved

advanced time question.

Posted on 2004-10-05
8
222 Views
Last Modified: 2008-02-01
Hi i need som kind of function to do my work. In my mysqltable i have a date ex 2004-10-05 14:00 and i need to check if it have gone ex 24hour. If you read my code i have post here you will propobly understand what i mean. And if it have gone more then 24h the script will not stop at
} if ($elapsed < $wait) {
            bterror("Not authorized (" . ($wait - $elapsed) . "h) - READ THE FAQ!");
            exit();
      }
I hope someone can help me with this question. I think it's kind a hard.



function ratiocheck()
{
      global $_GET;
      
      $ratio = 0.1;
      $gigs = 1;

      $hash = checkhash($_GET['info_hash']);
      
      $result = mysql_query("SELECT * FROM torrents WHERE p_hash = '$hash'")OR die (bterror("error in mysql"));
      while ($gtim = mysql_fetch_array($result))
      {
            $p_time = $gtim['p_time'];
         // $p_time is the time (2004-10-05 16:00)
      }
      
      $p_time = $elapsed;
      // ratio
      if ($ratio < 0.5) {
            $wait = 24;
      } elseif ($ratio < 0.8 || $gigs < 6) {
            $wait = 12;
      } elseif ($ratio < 0.9 || $gigs < 10) {
            $wait = 6;
      } elseif ($ratio < 1.0 || $gigs > 15) {
            $wait = 0;
      } if ($elapsed < $wait) {
            bterror("Not authorized (" . ($wait - $elapsed) . "h) - READ THE FAQ!");
            exit();
      }
}
//############################# SLUT #######################
0
Comment
Question by:stromberg10
8 Comments
 
LVL 13

Accepted Solution

by:
cLFlaVA earned 50 total points
ID: 12229068
You are not setting the $elapsed variable anywhere.  Maybe this line:

$p_time = $elapsed;

Should be this:

$elapsed = $p_time;

Or, you could remove the line altogether, and then make the final if statement look like this:

if ($p_time < $wait) {
          bterror("Not authorized (" . ($wait - $p_time) . "h) - READ THE FAQ!");
          exit();
}


Any reason you're screaming SLUT at the bottom of the code?
0
 
LVL 27

Assisted Solution

by:Diablo84
Diablo84 earned 50 total points
ID: 12230927
As a side note you do not need this line

global $_GET;

$_GET is a super global, you can access it in the function anyway
0
 
LVL 49

Assisted Solution

by:Roonaan
Roonaan earned 50 total points
ID: 12231993
You could use strtotime() to change the '2004-01-01 10:10' into a unix timestamp. You could then match this with the result from mktime() and look if the 24 hours have past:

if(mktime() < strtotime($p_date)  + $wait)
{
  //still in waiting periode
}
else
{
  //waiting period has passed.
}

Or I might understand your question incorrectly.

Regards

-r-
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 1

Assisted Solution

by:aot2002
aot2002 earned 50 total points
ID: 12233871
mysql> SELECT DATE_ADD('1999-01-01', INTERVAL 1 DAY);
        -> '1999-01-02'



http://dev.mysql.com/doc/mysql/en/Date_and_time_functions.html
0
 
LVL 14

Assisted Solution

by:ThG
ThG earned 50 total points
ID: 12238396

I think Roonan's answer should work. If you want a MySQL solution here it is:

mysql> select if(now() > date_add('2004-10-03 13:22:00', INTERVAL 1 DAY), 1, 0);

     $result = mysql_query("SELECT *,IF(NOW() > date_add(p_time, INTERVAL 1 DAY), 1, 0) AS elapsed FROM torrents WHERE p_hash = '$hash'")OR die (bterror("error in mysql"));
          $p_time = $gtim['p_time'];
        // $p_time is the time (2004-10-05 16:00)
        $elapsed = $gtim['elapsed'];
         // $elapsed is 1 if 24 hours elapsed, otherwise 0
     }
     
   
0
 
LVL 1

Expert Comment

by:aot2002
ID: 12238685
thanks ThG

i just wanted to make sure he had both options !
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now