They’re not needed if there’s only one statement to be executed.
Oh yeah. Lol. FWIW, the code works for me.
Yes my php is enabled and not show any error.
Once again may I have the code which you edit.
I copied the code from your initial post
Is there you nothing CHANGES?
Nothing
I tried the code and it worked. The only change was replacing the header
with an echo
for testing purposes, because that location does not exist.
$time = date('G'); //24 hour without leading zeroes
if($time >= 9 && $time <= 21)
$loc = 'good.php';
else if($time >= 21 && $time <= 3)
$loc = 'bad.php';
else if($time >= 3 && $time <= 8) $loc = 'sleep.php';
if(isset($loc)) {
echo 'location is '. $loc ;
//header("Location: https://website.com/{$loc}");
exit;
}
But there is still this condition that does not make sense:-
else if($time >= 21 && $time <= 3)
Thank the problem have solved actually my code was correct . The problem was came from here…
I just correct the time and the problem has fixed …
Thanks engineer!!!
This means from 09PM to 03 AM=bad.php
In that case, you want OR not AND.
That may be your intention, but:-
Change &&
(and) to ||
(or)
For “and” logic to return true, both conditions must be met.
With “or” either can be met to return true.
<?php
$time = date('G'); //24 hour without leading zeroes
if($time >= 9 && $time <= 21)
$loc = 'good.php';
else if($time >= 21 && $time <= 3)
$loc = 'bad.php';
else if($time >= 3 && $time <= 5) $loc = 'sleep.php';
if(isset($loc)) {
header("Location: https://abcd.com/{$loc}");
exit;
}
?>
I have timing issue yet…
I want;
See posts above.
No one is going to write the code for you. You have been given all you need. Just put it together.
It is a simple correction to the logic which you should be able to complete very quickly and easily yourself.
Change the and to or, that is all.
Is there only required " || " instead of " &&" ?
<?php
$time = date('G'); //24 hour without leading zeroes
if($time >= 9 || $time <= 21)
$loc = 'good.php';
else if($time >= 21 || $time <= 3)
$loc = 'bad.php';
else if($time >= 3 || $time <= 5) $loc = 'sleep.php';
if(isset($loc)) {
header("Location: https://abcd.com/{$loc}");
exit;
}
?>
Is this correct?
No. Only the “bad” condition should be or
.
Think about the logic…
I am confused about times (>/<)
What I do where I change
For:::