-5
if(){ 
    header ('Location: http://www.misitio1.com'); 
}else{                 
   header ('Location: http://www.misitio2.com'); 
}

I have this until now. How do I add the time to the conditional, and when the seconds or minutes are even, redirect to site1 and when odd redirect to site2.

Bowdzone
  • 3,827
  • 11
  • 39
  • 52

1 Answers1

1

Try this

$time = strtotime("now"); // You will get the current time in UNIX timestamp..


if(($time%2)==0){ 
    header ('Location: http://www.misitio1.com'); 
}else{ 
    header ('Location: http://www.misitio2.com'); 
}

If you want to work on the value of the current hour or minute,

$hr = date("H"); //Change it depending on your wish, 12 hr or 24 hr time. This will return 24 hr time.
$min = date("i");

if((($hr%2)==0) || (($min%2)==0)){ //You can add condition as per your requirment
    header ('Location: http://www.misitio1.com'); 
}else{ 
    header ('Location: http://www.misitio2.com'); 
}
NewBee
  • 394
  • 3
  • 15
  • @LuisCesar Please don't call me a genius. Thank you, upvotes etc is enuf. Maybe you are new to it so it was difficult for you. Once you learn it you will understand it, it's all about logical tricks and some performance tunings. My knowledge is limited to my hobby site. I know only what I have used there. I'm happy it worked for you. – NewBee Jun 10 '18 at 22:23
  • 1
    @user3783243 missed the quotes, edited. I have purposely used `strtotime("now")` instead of `time()`. No special reasons, just like that. – NewBee Jun 10 '18 at 22:29