Welcome Guest, Not a member yet? Register   Sign In
Server time returns value 8 hours ahead
#1

[eluser]edidiway[/eluser]
I have a strange problem, I am using codeigniter and hosting my application in godaddy server.
I tried to get the server time using this syntax

Code:
date('Y-m-d H:i:s')

this is a simple syntax right ?
but sometimes the time is right, but sometimes the time returns 8 hours ahead from now.

I dont know why this thing can be happened.

my .htaccess code is like this :

Code:
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]

can anyone give solution for me ?
I have tried called godaddy support, but there is no solution.


#2

[eluser]PravinS[/eluser]
It may be due to server timezone, please check the URL

http://php.net/manual/en/timezones.php
#3

[eluser]InsiteFX[/eluser]
Or you can add this to the top of your index.php file, make sure you change the location to yours.

Code:
/**
* Set the default timezone, you should not need this on a live server.
*/
date_default_timezone_set('America/New_York');
#4

[eluser]edidiway[/eluser]
thanks for all your reply,

but I think the problem is not in timezone.

example, I tried to give this code :
Code:
date_default_timezone_set("Asia/Jakarta"); //located in index.php
echo ('Y-m-d H:i:s);

the time was accurate sometimes with current setting, but sometimes wrong.
Is there any setup I must do ? or is there someone who have experienced the same problem with me ?

for your Info I host my web application on godaddy server where the default timezone is : America/Phoenix
#5

[eluser]PravinS[/eluser]
if you have added it just for index.php file, then it will work only for index.php

you can add this code in any common php file and include that file in all php pages, so it will work for all php pages
#6

[eluser]Pert[/eluser]
As everything runs through index.php file in CodeIgniter, that's the only place you have to set it.

Is it only PHP date function that shows time wrong?
#7

[eluser]edidiway[/eluser]
sorry for the late reply..

@pravins
like Pert says, everything in codeigniter run through index.php, so it is enough to set timezone on index.php file

@Pert
not only the date() function shows time wrong, but also mdate() function..

anyone can help me ?
I am confuse because I have 2 web application with 2 account on godaddy server,
the one is accurate, but the other one is not (even I use the same file and the same code)




Theme © iAndrew 2016 - Forum software by © MyBB