mercredi 21 octobre 2015

What's wrong with my PHP datetime code?

I'm not experienced with PHP. I'm loving it so far, except that this bit of code is working sometimes and other times not at all.

I'm trying to redirect based on the time of day. I have this script set up on multiple domains, with different times for each. Sometimes it works correctly, and sometimes it does not. I have modifed my php.ini file as well as .htaccess to try and set the timezone. I have tried writing the time in CST which my server is in(Hostgator), but no luck there either. I should note that there is some HTML that follows my code here, but it's outside of the php.

It doesn't make sense to me why it only works SOMETIMES. I've tried clearing my browser cache many times but it never helped. In this code, it should only display the html below it between 5:47 PM and 6:43 PM and redirect at all other times, right? Is it some sort of caching issue? Is the script being stored and then not being executed when I visit multiple sites in a row? Any help is greatly appreciated.

The best case scenario is this is only happening to me because I am visiting the sites too much to make sure the script is working correctly. Is that possible?

<?php
date_default_timezone_set('America/Los_Angeles');
$hour = date("G");
$min = date("i");

if(($hour >= "0" and $min >= "00") and ($hour <="17" and $min <= "47"))
    {
    header('Location: http://mysite.php');
    exit();
}
elseif(($hour >= "18" and $min >= "43") and ($hour <="23" and $min <= "59"))
    {
    header('Location: http://mysite.php');
    exit();
}
?> 

Aucun commentaire:

Enregistrer un commentaire