Solved

advanced time question.

Posted on 2004-10-05
8
223 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
how to create a scatter graph with straight lines 6 27
count download link and run update query 9 56
php refresh button on the browser 2 36
Download a website to hdd 2 50
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

920 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

13 Experts available now in Live!

Get 1:1 Help Now