xyn Posted September 25, 2006 Share Posted September 25, 2006 Hi Guys,I am looking into making time bans, allowing my mods to ban someone foreither 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... Link to comment https://forums.phpfreaks.com/topic/22032-time/ Share on other sites More sharing options...
Caesar Posted September 25, 2006 Share Posted September 25, 2006 [quote author=xyn link=topic=109471.msg441308#msg441308 date=1159219415]Hi Guys,I am looking into making time bans, allowing my mods to ban someone foreither 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...[/quote]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....[code]<?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!!';}?>[/code] Link to comment https://forums.phpfreaks.com/topic/22032-time/#findComment-98564 Share on other sites More sharing options...
Barand Posted September 25, 2006 Share Posted September 25, 2006 If you want to ban for $x days[code]$ban_until = strtotime ("+$x days);[/code]Similarly, to ban for $x hours[code]$ban_until = strtotime ("+$x hours);[/code]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 Link to comment https://forums.phpfreaks.com/topic/22032-time/#findComment-98567 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.