Log in

View Full Version : Whats wrong with my script!



Decode
20-08-2008, 12:23 PM
Ive made a function to unban an acount from my usersystem automaticly, when they login on a banned account this function executes (ive removed the getting the unban time from the database from the top and replaced it with $date so its eaysier to understand)


$date = "21/08/2007 14:38";

$datetime = explode(" ", $date);
$timeexplode = explode(":", $datetime['1']);

$dateexplode = explode("/", $datetime['0']);

$dateday = date("d");
$datemonth = date("m");
$dateyear = date("Y");

$timehour = date("G");
$timemin = date("i");

function unban()
{
//unban function
echo "unbanned";
}

if ($dateyear >= $dateexplode['2']) {
if ($datemonth >= $dateexplode['1']) {
if ($dateday >= $dateexplode['0']) {
if ($timehour >= $timeexplode['0']) {
if ($timemin >= $timeexplode['1']) {
unban();
}
}
}
}
}
?>Ive been looking for an error for about 20 minutes but I can't find one +rep if someone can help me :)

Moved by Invent (Forum Moderator) from Designing & Development: Please post in the correct forum next time, thanks :).

Invent
20-08-2008, 01:15 PM
The issue is with lines like this:


if ($dateday >= $dateexplode['0']) {
Your checking if today (the 20th) is more than the day you've preset (if you get me lol) which in this circumstance it isn't...

So you're checking if the 20th is more than the 21st, lol.

Decode
20-08-2008, 01:27 PM
But wouldn't that be right then, $date is the unban date so if the 20th isnt more than the 21st it does nothing, but if it is it checks the time. I have allso tried putting the date as the 20th with the unban time before the time now, but it wouldn't work.

Sorry if what i said was confusing, im not very good at explaining it :P

Ryzie
20-08-2008, 01:32 PM
Use the PHP time() function.
This gets the amount of seconds from 1 January 1970 or something.
Then simply, add the amount of seconds, for example, 2 hours; 7200 seconds (60 x 60 x 2).
Then, you set this into a database; time() + 7200.
Then, if(time() >= databasetime){
unban;
}

Hope this helps... :)

Decode
20-08-2008, 01:43 PM
Thanks Ryzie :) Thats a lot eaysier than all those ifs :)

Want to hide these adverts? Register an account for free!