Terry Posted April 5, 2011 Share Posted April 5, 2011 I found something strange during a debug session for footer.html upto page 71 in the second part of the book where the basics of the index.php file is being created. I am building this on my testing environment: Win XP PRO SP3 Vertrigo Server Apache 2.0.64 PHP 5.2.7 MySQL 5.0.51a From the book pg 69 end of part 3 and begin of part 4 if(isset($_SESSION['user_admin'])) { echo '<div class="title"> ... .. snipit .. </ul> '; } <--- Closes if user admin IF statement } else { during my handcoding from the book I left out the closing bracket for the IS ADMIN IF statement so the above looked like if(isset($_SESSION['user_admin'])) { echo '<div class="title"> ... .. snipit .. </ul> '; } else { I was getting THIS ERROR An error occurred in script 'D:\_intranet\home\resources\ecom1\includes\footer.html' on line 42: include() [function.include]: It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Chicago' for '-5.0/DST' instead It was hell tracking down the issue but I figured it out. As I see it, at this stage in the code there is NO reference to any time or date functions. Why would this error be thrown? Once I discovered the missing bracket I fixed it and the error above went away. I guess this is more a novelty than anything but I am curious why a date time formatting error? Is it reading from the database the date fields and PHP doesn't know what format the time zone is suppose to be? I dunno, found this odd and posting what I experienced. Dunno. Thanks. Link to comment Share on other sites More sharing options...
Jonathon Posted April 5, 2011 Share Posted April 5, 2011 The database provides the times things happens and php can use that info in its results. But date_default_timezone_set() sets the timezone for php to use. There also might be an option in your php.ini file to set it. 1 Link to comment Share on other sites More sharing options...
Stuart Posted April 5, 2011 Share Posted April 5, 2011 The error only appears as of PHP 5 and only if you have error reporting set to strict. Team PHP decided that it should be good coding practice to explicitly set you timezone using date_default_timezone_set. With regards to not using any datetime functions - this is only a guess but I presume at some point in the config that you will have defined a custom error handling function. Inside that function there will probably be references to functions that are either explicitly or implicitly calling datetime functions. For example it's quite likely that error_log would use some form of datetime functionality behind the scenes. Therefore when you omit the closing brace causing an error, it throws a syntax error, your error handler is called and this results in the timezone related warning. I don't know if thats true but it seems logical and the only explanation I can think of... 1 Link to comment Share on other sites More sharing options...
Terry Posted April 5, 2011 Author Share Posted April 5, 2011 Thanks for responding. I set the time zone in the index.php file at the time zone error went away. I am just using the code from the beginning of the Second Section of the book the Paypal project. I don't see any time or date BUT there is a custom error handler which does get time/date from the system so I guess that is where that error is triggered from. It makes sense now. Thanks. P.S. I do not know if error handling is set to strict. This is what Larry has for setting the error handler "set_error_handler('my_error_handler');" then the function outputs number of the error, error message, file error occured in, line number of error and then all the set variables. Link to comment Share on other sites More sharing options...
Stuart Posted April 5, 2011 Share Posted April 5, 2011 I'm pretty sure it must be set to strict in order to receive that error message - certainly not a bad thing. It will either be set at runtime using something like: ini_set('display_errors',1); error_reporting(E_ALL|E_STRICT); Or it will be set in your php.ini file which is often out of your control in shared hosting environments. I personally always develop with error reporting set to it's highest level to ensure I'm producing the best code possible. As far as I'm aware errors, notices and warnings continue to be generated with error reporting turned off which is just a waste of your servers resources. But in a live site you'd want to alter error reporting to prevent them from being shown on a live site which could provide valuable information to malicious users - I suspect the my_error_handler function Larry wrote for this book will take care of this live/development status and adjust error handling appropriately. PS Almost forgot this - I once altered the error reporting level to strict on one of my first ever sites which mean't all errors we're being emailed to my inbox. After receiving 75000 emails in a matter of hours - my advice is to develop on the highest level at all times!! 1 Link to comment Share on other sites More sharing options...
Terry Posted April 5, 2011 Author Share Posted April 5, 2011 In my php.ini file on my testing environment I have: error_reporting = E_ALL & ~E_NOTICE I don't see anywhere I have specific STRICT setting for errors. Link to comment Share on other sites More sharing options...
Recommended Posts