Solved

date_default_timezone_set causes fatal error when https

Posted on 2007-11-17
7
2,837 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Portable, direct connect server access

The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

 
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

737 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