Time Base Redirect


#21

They're not needed if there's only one statement to be executed.


#22

Oh yeah. Lol. FWIW, the code works for me.


#23

Yes my php is enabled and not show any error.


#24

Once again may I have the code which you edit.


#25

I copied the code from your initial post


#26

Is there you nothing CHANGES?


#27

Nothing


#28

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)

#29

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!!!


#30

This means from 09PM to 03 AM=bad.php


#31

In that case, you want OR not AND.


#32

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.


#34

<?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;


#35

See posts above.


#37

No one is going to write the code for you. You have been given all you need. Just put it together.


#38

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.


#39

Is there only required " || " instead of " &&" ?


#40

<?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?


#41

No. Only the "bad" condition should be or.

Think about the logic...


#42

I am confused about times (>/<)
What I do where I change
For:::