If you notice the incorrect time in your PHP scripts, the likely culprit is that the hosting hệ thống is in a different timezone.
Bạn đang xem: Không an toàn khi dựa vào cài đặt múi giờ của hệ thống
Đang xem: Set date time zone php
For example, when you’re an InMotion web hosting customer, you can select from data centers in Washington, D.C. or California, which means the server’s timezone will be either Eastern Standard Time (EST) or Pacific Standard Time (PST).
If you want to change that, it’s a quiông chồng fix. Simply insert a line of code inkhổng lồ your php.ini tệp tin & the location you phối in the code will determine the time to lớn display in your PHPhường. scripts. Keep reading khổng lồ learn how.
Mục lục nội dung
How khổng lồ Set the PHP Timezone:
Open your php.ini tệp tin with the File Manager in cPanelAdd the following line of code khổng lồ top of your php.ini file: date.timezone = “US/Central”
Nanook says: February 4, 20đôi mươi at 8:27 am
Painful lesson for those application folks who three weeks ago say that they went though their testing (regressive?) & they come lớn you và tell you things are on fire. I guess as person that upgraded it, I should have checked it myself.
Ahmad says: October 12, 2017 at 9:04 pm
I have sầu changed the timezone ini.php tệp tin & its changed there successfully even i tested with phpinfo.php it showing there same as per my chnages. but the time on my website still same as before (wrong time). So, please advice what to lớn do?
InMotionFan says: October 12, 2017 at 9:27 pm
We are happy lớn help you troubleshoot further but will need some additional information. How/where is the time displaying on your website? Can you provide a link lớn the site for us lớn see the time?
Thank you, John-Paul
locortez says: September 28, 2017 at 5:12 am
Hi, can you teach me how khổng lồ configure VPS? i’m having trouble because i dont have sầu php.ini tệp tin in my public html
InMotionFan says: September 28, 2017 at 3:21 pm
I recomend contacting Live sầu Support so they can copy the server’s mặc định php.ini tệp tin khổng lồ your trương mục. You can then modify the php.ini as described above sầu.
Thank you, John-Paul
Website Designing says: August 1, 2017 at 7:42 am
Great tutorial. This tutorial was really useful to mix timezone.
Php Speciadanh mục says: June 12, 2017 at 10:11 am
Nice tutorial.This tutorial was really helpful to me on set timezone.
radha says: May 10, 2017 at 8:34 am
I set timezone as asia/kolkata in my VPS but it showing 4 minutes ahead than actual timezone time,plz help mee.
InMotionFan says: May 10, 2017 at 9:02 pm
If you made the change in the php.ini tệp tin then it’s possible that you have sầu another PHP.INI file where the change is not taking precedent. Make sure that the php.ini tệp tin with the time zone setting is recursive sầu. Here’s an article on how to lớn vị this: How lớn make my php.ini tệp tin recursive sầu. If the problem continues, then please let us know.
If you have any further questions or comments, please let us know.
Regards, Arnel C.
Tlặng says: September 16, 2016 at 7:44 am
What you are specifically looking for in this case for West Africa, và would be the same no matter where in the world you are is to find out first what your UTC offphối is & then use one in the danh sách that matches that. For example, I live sầu in the Pacific Northwest in the USA và our offset is -7 (that is minus seven) & at present we are in Daylight Savings time (aka PDT). When not in DST time of year we are -8 PST.
So we are minus seven hours from GMT aka UTC which is at 0 & sometimes expressed +0.
Xem thêm: những tin nhắn khiến nàng vui
Short answer is find your offphối & use the one that matches. There are many and I think some with the same UTC offset.
InMotionFan says: October 12, 2016 at 6:58 am
There is no php.ini in any accounts in my reseller tài khoản – all sites that check date get the php warning about timezone. The .htaccess fix does not work. Do I need khổng lồ request a php.ini file created every single time I create a site? This seems excessive sầu. It seems leaving warnings on as a default is a problem.
InMotionFan says: December 18, năm 2016 at 10:26 am
On my VPS, phpinfo() says user_ini.filename.user.ini
So instead of php.ini, I had to create .user.ini in the cPanel’s /public_html/ directory for the date.timezone setting khổng lồ take effect on my site.
InMotionFan says: December 18, 2016 at 10:27 am
…which also requires your cPanel File Manager Settings be set khổng lồ Show Hidden Files (dotfiles).
Mark Thomas says: September 15, 2016 at 2:37 pm
I found this helpful.
When no mặc định is set, it goes lớn UTC. This is what I found with one hệ thống.
For another it was mix to Germany/Berlin !
I updated php.ini, but phpinfo() did not update even when pressing F5, until I recycled apađậy. Then I went into lớn the phầm mềm & the times were correctly displayed.
Mark says: September 13, 2016 at 6:27 pm
how can i change the time zone to lớn west africa as in nigeria,
i did not see it in the timezone list
InMotionFan says: September 13, 2016 at 7:27 pm
PHP does not have a timezone specification for Nigeria specifically, but it has one for Lagos.
Larry Greenhaw says: October 30, năm ngoái at 9:15 am
I have set date.timezone = “America/New_York” in my php.ini & set it recursive sầu in my .htaccess.. Still getting Los Angeles on my phpinfo page.
InMotionFan says: October 30, năm ngoái at 6:08 pm
Thank you for contacting us. Did you add the setting to the top of your php.ini file?
Can you provide a link to lớn your site for us to lớn test?
Thank you, John-Paul
Fachry says: July 30, 2015 at 7:12 am
THank you,, it worked for me..
BR From Indonesia
Lucas says: May 28, năm ngoái at 9:05 pm
GREAT! Now it works with my timezone! Thank you very much!
Best Regards from Brazil! ????
Andy says: April 4, 2015 at 2:12 am
I would like to lớn know how to go baông chồng automactically lớn home page 3 seconds after submitting the data. I’d tried with header but it goes bachồng và forth. Please guide me through that. Thanks a lot for your time.
InMotionFan says: April 4, 2015 at 3:35 am
Unfortunately, providing programming tư vấn is beyond the scope of our tư vấn. Please consult with a developer or forum that helps with programming a solution khổng lồ meet your needs.
Regards, Arnel C.
hermit says: March 28, năm ngoái at 7:33 pm
I just moved my accounts khổng lồ IM and am testing. I went to lớn a Members Only login page and got two errors re: php that I am not getting on the old server. I checked the version of php & mix it khổng lồ the same 5.3 that it was using before.
Warning: session_start() : It is not safe to lớn rely on the system’s timezone settings. You are *required* lớn use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods và you are still getting this warning, you most likely misspelled the timezone identifier. We selected ‘America/Los_Angeles’ for ‘PDT/-7.0/DST’ instead in /home/uscold/public_html/mo/membersOnly.php on line 6
Warning: session_start() : open(/tmp/sess_e079720753ff740ed0a801cea301a3d3, O_RDWR) failed: Permission denied (13) in /home/uscold/public_html/mo/membersOnly.php on line 6
I tried adding the line in php.ini for the timezone as instructed on this page but am still getting these errors. Can you point me lớn a solution? Thanks. (I’m not knowledgeable in php beyond very simple basics)
If the times that the data is logged in your DB are according lớn GMT (example being) then you can vì chưng a fairly simple convert according to what UTC offset by adding or subtracting an hour (eg. 3600 seconds per hour if logged using a Unix Timestamp).
As for further entries in the DB, I would recommend lớn use the same method as has been used khổng lồ this point unless an upgrade is in order. In which case, change relevant data points lớn match as you desire and & for all previous data, use a conversion script.