Jump to content


Photo

Time...


  • Please log in to reply
2 replies to this topic

#1 xyn

xyn
  • Members
  • PipPipPip
  • Advanced Member
  • 779 posts
  • LocationNorthampton

Posted 25 September 2006 - 09:23 PM

Hi Guys,
I am looking into making time bans, allowing my mods to ban someone for
either x hours, x days, or x minutes, What would be the easiest way?
I've been thinking bout "d/m/y" and "H:i:s" but i don't think it will work...

#2 Caesar

Caesar
  • Members
  • PipPipPip
  • Advanced Member
  • 1,025 posts

Posted 25 September 2006 - 09:38 PM

Hi Guys,
I am looking into making time bans, allowing my mods to ban someone for
either x hours, x days, or x minutes, What would be the easiest way?
I've been thinking bout "d/m/y" and "H:i:s" but i don't think it will work...


Use timestamps. Don't store the times in the database as a formatted date. Timestamps can then be compared more easily in the code AFTER you run your SQL queries. Maybe something like this....

<?php

$query = $db->query("SELECT * FROM banned WHERE user = $userinfo[username]");
$btime = $db->fetch_array($query);

$time = time();
$maxbtime = ($time - $btime[ban_time]);
$hours = date("h",$maxbtime);
$minutes = date("i",$maxbtime);

if(YOUR CONDITIONAL CRITERIA HERE){

echo'Hey punk, you\'re still banned from these here forums!!';

}
?>

PHP Ninja

#3 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 25 September 2006 - 09:49 PM

If you want to ban for $x days
$ban_until = strtotime ("+$x days);
Similarly, to ban for $x hours
$ban_until = strtotime ("+$x hours);

As Caesar suggests, store the resulting $ban_until in the table (integer field will do it)

You can see if the ban is still in effect by comparing with time() function, which gives the current timestamp
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users