Date_default_timezone_set() returning incorrect results

wonder if this is a result of the time change yesterday? I have this code to capture renders:

$ip = gethostbyaddr($_SERVER['REMOTE_ADDR']);
$host = $_SERVER['HTTP_HOST'];
$page = isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : '';
date_default_timezone_set('America/Chicago'); //change server time zone to UTC-600 (Chicago, IL time)
$date = date("Y/m/d");
$time = date("H:i:s");

and the report prints this out:

and the actual time in Chicago at the time of the report view was:

anyone else complaining of this?

Well, it could be your server did not get updated to the correct time.
So, yes, it could be Daylight Savings Time not catching up on your server.
Is this your own server? If it is a shared server, such as Godaddy or others, it might take a few hours to catch up to correct itself. Also, your time on your computer is not the server’s time unless it is running on your computer. Is it an Wamp or other type of server?

the time I showed on the computer Ernie is irrelevant and yes it is my own local machine and no it is not the server that’s housing this website however like I said that is irrelevant. Because the PHP code is setting the time for the actual files as Chicago time in the usa. So it makes no difference if the server is even located in a China warehouse. and yes the server is managed by GoDaddy so I have no doubt that those guys screwed it up because they’re the most incompetent people in the world.

Do you remember months ago when we worked on the server from GoDaddy blocking my mailing attempt using PHP code? You worked with me on it for 3 days and we posted 60 times back and forth before we finally got the damn thing solved. And if I remember right, you said in one of your posts that during your tests to help me out you found out a few things about where your own server was located that you didn’t know.

Well, perhaps I did not explain clearly. If the server is NOT yours, then, they control the time on the server.
Changing the date in PHP does not actually change the server’s time. It changes the time-zone. Meaning that it changes the number of hours from GMT. So, if the server is still at another time, it will still be wrong and not match Chicago’s time. Usually, the remote server, shared or dedicated will catch up withing 24 hours. Some change quicker than others.

You can test if your system is running in DST with this command:

if (date('I', time()) == 1) ... the time is in DST mode ("0" = not)

That will at least tell you if your server is in the correct mode or not. And, you can use this to check if the correct timezone is actually set:
echo date_default_timezone_get();

Not sure if all this helps… Good luck with it…

It’ll help just fine Ernie thanks for the help. I talked with GoDaddy before I saw this latest reply of yours and he just spouted off information about migrating to a virtual private server and paying the company to do that period so that’s typical of a company that wants money when there’s a free solution available obviously. So I’ll figure it out without him and with your help thanks

I had that same problem with one of my sites. A NFL football pool. But, it seems to not be a problem now.

You could write a simple script to check for DST and adjust depending on the results. You would have to put in some dates to check, but, should not be very hard.

Anyway, goodnight and good luck with it…

Good night Ernie I told GoDaddy I’d check it in 2 days

Maybe I missed this… but do you have a php.ini file that sets the timezone?

date .timezone = America/Chicago

Whispers, Godaddy doesn’t give you a direct access to the php.ini file. It a “shared” server system.
But, he can adjust it using a script if it doesn’t straighten out in 24 hours…

That’s why they constantly push the concept of virtual private servers on me ernie. but my employers don’t have budgets for those and I don’t want to learn it anyway because I’m not a button clicker and if I were to run my own web server anywhere I would buy it at a local store and figure out myself because there’s no way in hell I’m going to give any access whatsoever to a company like GoDaddy who supposedly manages billions of servers around the world and no one knows anything because all they do is click buttons and hope the automation does the best by scanning massive networks LOL

So it doesnt even recognize/run/execute LOCAL .ini file in any (sub) directories??

Well, they have settings in their PHP control panel, but, usually it is not the same items that are in the PHP.INI file. So, you need to use PHP itself to set options and you need to do them on every page or in a base config file of some sort. There is no LOCAL system in a shared server. Basically, it is a large computer running dozens or more servers on it. But, yes, it does run commands in sub directories. Not sure what that question really was…

This doesnt make much sense to me:

“Godaddy doesn’t give you a direct access to the php.ini file. It a “shared” server system”

That would suggest that everyone using this shared server is stuck with ‘global’ PHP.ini settings… (which wouldnt be very practical…)

Thats not how it works for the hosting we have for 90% of our clients… (and they are all on a shared VPS plans) (we dont have to go through any ‘global’ control panel to set settings)… this can be done with ‘local’ files, in ‘local’ directories…

These ‘servers’ are technically located on the East coast… so we put in specific/local php.ini files to set the times zones… along with other things…etc…

such as error reporting… or specifically designating a (legacy) directory to run PHP 5.6 still (until the project files can be updated to using PDO/PHP 7.x compliant code)

So maybe thats how ‘GoDaddy’ is… not allowing for local .ini files to be executed if what your saying is true?

hey you guys,

everything has reverted to the way it was. so Ernie, it seems as though you were right. it was a temporary issue. I do not need to do anything. thanks much folks. =)

Whispers, yes and no! The shared Godaddy servers do give you access to some of the PHP options.
BUT, not the actual php.ini file. So, you can change the options they let you get to in the control panel.
Not all of the options in a real server system. UNLESS, you purchase their much more expensive full
dedicated server which gives you a full “blade” in their server house.

Vba_php, Good! I thought that would happen. Their server updates take up to 48 hours as I do still have
one of their servers up online and things like this take a bit to become active. So, glad to hear that!

10 posts were split to a new topic: Cant Log In To Forum

The system time on the server is what it is. If the people maintaining that computer don’t have the time set correctly, there is nothing you can do about it.
However, If you want to create a file in the webroot called .htaccess you can put this line in it

php_value date.timezone ’ Americqa / Chicago

That way, your default time on your site will be set to Chicago time.
There are many things that you can do with .htaccess
This is a special file that has no name but the file type is htaccess
I hope this is not off-topic.

Sponsor our Newsletter | Privacy Policy | Terms of Service