My web host recently migrated to a new server and in the process upgraded to PHP5.4
I have a snippet that was doing timezone conversion, but since the upgrade the script stops dead on a certain line in the snippet, and though a web page is displayed, none of the content (including html) displays beyond that PHP line.
Here is the code with the problem lines commented out:

<?php 
$timestamp = strtotime($create);
$dtzone = new DateTimeZone($tz);
$time = date('r', $timestamp);

/* Problem code begins here
$dtime = new DateTime($time);
$dtime->setTimeZone($dtzone);
$time = $dtime->format('F d, Y');
Problem code ends here*/

echo $time;
?>

$create and $tz are values drawn from a database and are specifically a creation date for the row and a timezone. By commenting out the three lines the rest of the script proceeds OK. Can anyone see what could be wrong here. If I run it on a WAMP server using PHP v 5.4.3 the thing is fine. If you can see what is wrong an explanation as well as a correction would be most welcome. (I have no idea how to insert a block of code. Can someone enlighten me?)

Recommended Answers

All 21 Replies

the script stops dead on a certain line in the snippet

Do you get an error message?

No error. Earlier PHP and HTML code displays OK but everything from the problem lines on displays blank.

I've tried this, no issues:

<?php
$timestamp = strtotime('2013-09-25 10:13:00');
$zone = new DateTimeZone('Europe/Amsterdam');
$time = date('r', $timestamp);

$dtime = new DateTime($time);
$dtime->setTimeZone($zone);
$time = $dtime->format('F d, Y');

echo $time;
?>

I can give you access to the page to show what is happening.
For this exercise you can use the login try-me@safetytestingonline.com with the password basil1. It's a public demo page, so no harm with the login stuff.
If you go to Click Here and log in you will get the page as displays without the three lines commented out. If you then go to Click Here you can see the page with the three lines commented out.

Add error_reporting(0); to your script. See if you get error messages then.

I've added that line and uploaded the file. No error message.

I'm out of ideas, I can't reproduce this. Am sure someone else will chip in.

I have to wonder if some of the PHP in those three lines has become obsolete.

Thanks for your help anyway. I sure hope someone can help me out. I'm willing to post the whole code but it runs out to 270 lines.

Still no difference, both on online server and local server.

Member Avatar for LastMitch

$create and $tz are values drawn from a database and are specifically a creation date for the row and a timezone.

@facarroll

Try this query and see if the date is correct on your server:

SELECT CONVERT_TZ(NOW(),'CET', 'UTC');

On your php.ini file if you have one add these two lines:

date.timezone = "America/Your_City"
session.auto_start = 0 

On your php file add this (which pritaeas already mention)

error_reporting(0);

Then run your code again and see what error appear.

There should be an error explaining the situation.

Where do I place the query to check the server date?

Member Avatar for LastMitch

Where do I place the query to check the server date?

Run the query on your database.

I got NULL.
Both on Wamp and online server
I guess this means I go to the Web Host and ask them to load the timezone data. Is this correct?
The WAMP server is Apache but the online server is Linux.

Member Avatar for LastMitch

I guess this means I go to the Web Host and ask them to load the timezone data. Is this correct?

@facarroll

No, this has nothing to do with the Web Host server, I don't think they set timezone. Usually it's on the Cpanel or some platform that let you put a php.ini file on the server.

Then you run the query on the database.

I've had a response from support. They suggested resolving it by including
date_default_timezone_set('Australia/Victoria'); at the beginning of the offending file and that did correct the file, but I've since found error messages occurring wherever a date function is called all over the web site. I do have a php.ini in /public_html on the server and this was reading date.timezone = "Australia/Melbourne"and I tried amending it to date_default_timezone_set('UTC'); but this didn't change anything. I am convinced that something is wrong on the remote server, because it all works fine on my WAMP server.
While I don't know much about php.ini, is it possible that there is another php.ini taking preference over the php.ini file I have placed in /public_html?

Member Avatar for LastMitch

I do have a php.ini in /public_html on the server and this was reading date.timezone = "Australia/Melbourne"and I tried amending it to date_default_timezone_set('UTC'); but this didn't change anything. I am convinced that something is wrong on the remote server, because it all works fine on my WAMP server.

You need a timestamp query to run on the database.

You can try this:

http://technet.microsoft.com/en-us/library/ms186819.aspx

On your php.ini file you should have these two lines:

date.timezone = "Australia/Victoria"
session.auto_start = 0 

Regarding about

date_default_timezone_set('Australia/Victoria');

that's for a file but the issue you are having is more related to a database issue.

You need to match the date code you have with the database timestamp. I think somewhere in your code, there is query that is not fetchin' the data correctly.

So that might be the issue, not sure can't dupilcate the issue you are having.

I've been able to get error messaging working and this is really weird (to me, anyway).
The error message generally goes like this
Warning: session_start() [function.session-start]: open(c:/wampserver/tmp/sess_4bkd7oiqmi7298mhikv09447t6, O_RDWR) failed: No such file or directory (2) in /home/safetyte/public_html/portal/woodwork_sub/ws_member_profile.php on line 2
Lines 1 and 2 are
<?php
session_start();
This message is coming from the remote server but refers to a folder on my local computer. This message is displayed on any computer that links to http://www.safetytestingonline.com/portal/woodwork_sub/ws_member_profile.php as well as several other online links, though not all.
Any help would be appreciated. My webhost isn't doing much for me.

I think I'll mark this thread as solved and start it again under "session:save_path error" because the original heading has become very remote from the topic.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.