Sherder Posted November 29, 2011 Posted November 29, 2011 Hey!I have added date which shows server time in my website. Unfortunately it shows almost every moment different time. So I can't code a site where I and the others can see when the users have been online and so on. Why is this happening?
Byron Posted November 29, 2011 Posted November 29, 2011 It's hard to help you with only the information you provided. Can you give us an example of what your talking about and maybe the code? BTW, the server is on Pacific Standard Time.
Sherder Posted November 29, 2011 Author Posted November 29, 2011 It's hard to help you with only the information you provided. Can you give us an example of what your talking about and maybe the code? BTW, the server is on Pacific Standard Time. Okay, so I have added to my website a PHP code: $datetime = date("Y-m-d H:i:s") When I put "echo" -command to the beginning it shows in my website time like "2011-11-29 21:24:48", but the problem is that time changes almost every time. I mean when I refresh the page it shows 2011-11-29 23:22:44 or 2011-11-30 06:21:21 and so on. So the problem must be at server. I don't even know how that is possible, because it shows the time of server. In my home computer it shows the time exactly correct and in other free web hosting site the time goes normally forward. Does your server change time constantly or something?
Byron Posted November 29, 2011 Posted November 29, 2011 This test page I made shows the time moving ahead just like it should. Does it do the same for you? http://byrondallas.heliohost.org/test/date-time.php <html> <body> <h2> <?php $datetime = date("Y-m-d H:i:s"); echo $datetime; ?> </h2> </body> </html>
Sherder Posted November 29, 2011 Author Posted November 29, 2011 Edit: It did it again. I see that it changes almost every time when it loads the page longer than usually. It does not always change but sometimes now. It seems to work in your site, but mine not. Please refresh my page very often few minutes and you will see how it changes:http://intr.heliohost.org/index.php
Piotr GRD Posted November 29, 2011 Posted November 29, 2011 For me it jumps 2 hours back and forward on your example.If I refresh it many times then usually it shows time in GMT-0800 (PST), but sometimes in GMT-0600 (CST), while byron's page display time in GMT-0500 (EST). Are you sure your script does not change the time zone used for some reason? putenv("TZ=XYZ");Do you have the same results if you'll echo just the time with having nothing more in the script?Eventually add to the script the following to confirm if the timezone is not switched:echo getenv("TZ");
Sherder Posted November 29, 2011 Author Posted November 29, 2011 I added putenv("TZ=XYZ") and getenv("TZ") to my website and I tested it again. The result was that the putenv and getenv did not change. It was only the time which changed... This is so unbelievable problem that I don't know how this could be solved. This is very strange. I can't make reliable system where I save users last activity to database etc. You can try again:http://intr.heliohost.org/index.php Edit:Now I got for example:2011-11-29 16:37:19putenv("TZ=XYZ"): 1getenv("TZ"): XYZ
Piotr GRD Posted November 29, 2011 Posted November 29, 2011 There is no such time zone like "XYZ". ; ) Sorry, that was just an example on my side.You may want to put "TZ=EST" or "TZ=America/New_York" etc. Place putenv("TZ=your_desired_timezone"); at the very beginning of your script and then the time for you should be displayed correctly (unless in some other place of your script you will change timezone again). All valid time zones you can find here:http://php.net/manual/en/timezones.php But I'm curious... if YOU (your script) don't change timezone randomly... why is this changing by itself?... I may test it later.
Sherder Posted November 29, 2011 Author Posted November 29, 2011 Oh, yeah, I'm so tired now because I'm from Finland and here is night at the moment . I have never used those timezone PHP commands before. But I have now added these in my website:putenv("TZ=Europe/Helsinki"): 1getenv("TZ"): Europe/Helsinki2011-11-30 00:54:12 When I now test my website the time does not change or then I didn't test very well yet. But it seems to work now because of changing timezone at the very beginning of my script with that putenv("TZ=Europe/Helsinki"); . I continue testing.
Piotr GRD Posted November 29, 2011 Posted November 29, 2011 Midnight for me in Poland. ; ) Anyway... additional note for you: Stevie's (the server your website is on) clock "jumps" back and forward 24 seconds (it's either correct or 24 seconds behind). Admins don't know why is that so far.Default timezone being switched may be related to the same problem. I think I'll test it when I'll find a time and inclination.
Sherder Posted November 29, 2011 Author Posted November 29, 2011 Aah okay, thanks for that info . BTW: I have now tested my site quite many times and it really seems to work now. Thank you very much for the help ! I think it really needed only that putenv code.
Byron Posted November 29, 2011 Posted November 29, 2011 An easier way to set the time zone for your site would be to add this to your root htaccess file: SetEnv TZ Europe/Helsinki That's how I set my time zone to EST. SetEnv TZ US/Eastern Then you don't need to set it in any of your php scripts.
Sherder Posted November 29, 2011 Author Posted November 29, 2011 Thanks to you too byron! I found htaccess file by search, but I can't modify it...
Byron Posted November 29, 2011 Posted November 29, 2011 Are you going through the cpanel file manager? You should be able to edit the htaccess file just like any other file.
Sherder Posted November 29, 2011 Author Posted November 29, 2011 Yeah, I found htaccess file with search through file manager, but when I click that file it just put me back to public_html -directory.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now