Jump to content

strtotime problem.


xyn

Recommended Posts

Hey Guys,
I've got a small problem, I've gt very confused on how to use
strtotime, so from what i've read from php.net i have managed
to create a "time ban" the only problem is checking the ban when
the user logs in,

I have set the ban in "Minutes, OR hours OR days" and using the
below code to set the ban, could someone help me with the "unban" check?
thanks...

[code=php:0] if($_POST[perm] == "never"){
$expire_date= "Never";
}else{
$date = strtotime("now + $_POST[time] $_POST[type]");
$expire_date = date("j, m, Y - H:i.s", $date);
$date_now = strtotime("now");
$now= date("j, m, Y - H:i.s", $date_now);
}[/code]
Link to comment
https://forums.phpfreaks.com/topic/22160-strtotime-problem/
Share on other sites

Firstly, I dont think that you need the "now" in your $date strtotime, and I suspect that the way you have it written is wrong.  Try either:

[code]$date = strtotime("+" . $_POST['time'] . " " . $_POST['type']);[/code]

or

[code]$time = $_POST['time'];
$type = $_POST['type'];
$date = strtotime("+ $time $type");[/code]

and as a shortcut

[code]$expire_date = date("j, m, Y - H:i.s", strtotime("+" . $_POST['time'] . " " . $_POST['type']));[/code]

For the $now time, you dont need to use strtotime, just having the code below will get the current date and time

[code]$now= date("j, m, Y - H:i.s");[/code]

So the final code would be something along these lines

[code=php:0]if($_POST['perm'] == "never"){
$expire_date= "Never";
}
else{
$expire_date = date("j, m, Y - H:i.s", strtotime("+ " . $_POST['time'] . " " . $_POST['type']));
$now= date("j, m, Y - H:i.s");
}[/code]

May require a bit of tweaking, but give it a go
Link to comment
https://forums.phpfreaks.com/topic/22160-strtotime-problem/#findComment-99237
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.