Solved

date_default_timezone_set causes fatal error when https

Posted on 2007-11-17
7
2,829 Views
Last Modified: 2010-04-21
Have a problem with date_default_timezone_set(). It causes the following error when the code in question is called via https:

Fatal error: Call to undefined function: date_default_timezone_set() in /htdocs/timetest.php on line 2

This error can be reproduced even to having just enough to call it as in the snippet below. This is problematic as it causes non fatal errors in our code with that set line commented out. I could leave it that way but would like to find out how to fix it. The code is running at 1and1 shared server.
<?php

date_default_timezone_set('America/New_York');

?>

Open in new window

0
Comment
Question by:Stacy Spear
  • 4
  • 2
7 Comments
 
LVL 48

Accepted Solution

by:
hernst42 earned 500 total points
ID: 20305516
See http://www.php.net/manual/en/function.date-default-timezone-set.php The function was introduced with php 5.1.x and it seems you have an too old installation of php.
0
 
LVL 21

Expert Comment

by:nizsmo
ID: 20305532
has hernst42 said, only available in php5.

2 workarounds:
echo date('H:i:s', strtotime('+2 Hours')); add/subtract how many hours you need to get your time right

or
Place this once at the top of your script:
setlocale(LC_TIME, 'en_UK', 'english-uk', 'uk', 'eng'); // adjust accordingly

And then use strftime() to format the date.

Hope this helps.
0
 
LVL 23

Author Comment

by:Stacy Spear
ID: 20305565
I am quite familiar with when it came out. The top of my .htaccess is:

AddType x-mapp-php5 .php
AddType x-mapp-php5 .php5
AddType x-mapp-php4 .php4

And has been so for sometime. This code works in http, just not https.

Thanks for the pointer, just ran a phpinfo() via http and https. http is the proper 5.2.4, https on the other hand is 4.4.7. Strangest thing I've ever saw.
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 23

Author Comment

by:Stacy Spear
ID: 20305572
I also want to state that this code ran great since January and just started giving errors Thursday. Maybe more info should have been given by me. :)

Going to call 1and1 to see what have they screwed up, unless you guys think my .htaccess can be changed, but I'm not aware of what to in this situation.
0
 
LVL 48

Expert Comment

by:hernst42
ID: 20305581
GUess the .htaccess is not used when run in https-mode. Guess the hoster misconfigured the server. Report the problem to their support.
0
 
LVL 23

Author Closing Comment

by:Stacy Spear
ID: 31409749
Made me think along other lines, which produced the solution, but still gave points.
0
 
LVL 23

Author Comment

by:Stacy Spear
ID: 20305726
Just for closure, 1and1 states that "PHP5 requires addhandler, not addtype" PHP5 and Apache are not the samething and Apache uses .htaccess. Oh well, that the add types to the following got it running again.

Addhandler x-mapp-php5 .php
Addhandler x-mapp-php5 .php5
Addhandler x-mapp-php4 .php4
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Microservice architecture adoption brings many advantages, but can add intricacy. Selecting the right orchestration tool is most important for business specific needs.
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now