Timezone does not work PHP

Asked

Viewed 461 times

3

When I give the command: echo ini.get('date.timezone') . "<br>"; nothing appears, I’ve set up in php.ini and nothing, also already put the default in the code and nothing either. Someone can help me?

  • What version of PHP are you using? Have you tried: echo 'date_default_timezone_set: ' . date_default_timezone_get() . '<br />';

  • Links that may help: http://php.net/manual/en/function.date-default-timezone-get.php and http://php.net/manual/en/datetime.gettimezone.php

2 answers

3


In my view it is a syntax error :

Substitute ini.get('date.timezone') for ini_get('date.timezone');

Example :

<?php
    echo 'date.timezone: ' . ini_get('date.timezone');
?>
  • Our only was the same syntax I’m pretty beginner yet. Thank you very much.

  • Who did not go through it, did not evolve, gave up, sure... we are there...

  • Thank you very much.

1

When syntax errors happen they are reported on screen, if it does not appear on the screen they are stored in logs, this data is very useful to solve problems or to ask questions to third parties who do not have access to the project.

In what environment are you developing the system? Since apparently the syntax error was not reported on screen probably PHP is configured not to display, if this is in production environment is correct, but if it is in development or test environment this "wrong"because it is good that the programmer is aware of the problems in the application.

How to check PHP/Apache error logs on a Linux system (Debian or derivatives):

Open the terminal and command tail -f /var/log/apache2/error.log this command will be monitoring the Apache error file so each test will show the new information entered in the log, to make things clearer with each test you can press the key Enter to open a space between the last error and the next to view to be simpler. These spaces (Enters) will not be saved in the Log. To get out just precional Ctrl + c;

How to check PHP error logs in Windows:

WAMP: Follow the steps:

1 - Right-click the wamp icon near the clock

2 - Go to the PHP submenu

3 - And click PHP Error Log

This way you will have to reload the file every time you make a new test, using Sublime Text 3 to open this log it will identify a change in the contents of the file and ask if you want to reload it by clicking on sim he’ll update for you.

XAMP: in the same way as at WAMP

Obs.: if you have installed Apache and PHP direct just give a quick search on the net that you find easy. However I have never seen anyone installing in a way direct.

Configuring PHP to report errors on a Linux system (Debian or derivatives):

Open the file php.ini here is located in /etc/php/5.5/apache2/php.ini locate the following lines or add at the end of the file

error_reporting = E_ALL
display_errors = On
log_errors = On

The option error_reporting defines the type of error level that will be reported, E_ALL report all. It is not legal to report errors in a production environment as malicious users may and will use this information to break into your system. In development and testing environment is highly recommended E_ALL not to let any mistake pass to the production environment.

The option display_errors sets whether errors will be reported on screen if you wanted to put on after the sign of equal if you do not want to place off

The option log_errors sets whether errors will be reported in the log if you wanted to on after the sign of equal if you do not want to place off

This form of configuration also applies to the Windows environment since it is a particularity of PHP, what changes is only the file path, This is assumed because I do not work developing in Windows but in Linux, since my systems are hosted in Linux.

  • 1

    Complete your answer by indicating a way to verify this... I think it is relevant what you are proposing...

  • I am developing in Netbeans, I tested another code only that purposely wrong and signaled yes, only that of my question that was not flagged.

  • 1

    @Right Magichat will complete... Rodolfoallesson in case you are using Windows and development environment, right? So since you tested another syntax error and PHP returned the error, what happened in your case may be out of the errors that are reported. I will complete my answer and put in how to verify it.

  • 1

    @Mateusfmello I’m actually using Ubuntu, but I tested on another machine with Windows and happened the same, I thank you for the reply friend.

  • 1

    @Rodolfoallesson is happy to see this, so my tips that I just passed in my answer will help you a lot, remembering that Ubuntu is derived from Debian, so I imagine you won’t have any problem running the tips if you think it necessary. And do not forget to score as a positive response to give a strength :D

  • 1

    @Mateusfmello Thank you so much for the tips friends, were very valuable to me, you are already master kkk.

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.