Query empty message

I am really sorry, but I do not know when I will come out of the newbie stage. Where and how do I place this script. I placed it before the line containing the timestamp and I got the following message.

Fatal error: Uncaught exception ‘Exception’ with message ‘DateTimeZone::__construct() [<a href=‘datetimezone.–construct’>datetimezone.–construct</a>]: Unknown or bad timezone (server/timezone)’ in /home/jppp/public_html/Discussion-board/index.php:60 Stack trace: #0 /home/jppp/public_html/Discussion-board/index.php(60): DateTimeZone->__construct(‘server/timezone’) #1 {main} thrown in /home/jppp/public_html/Discussion-board/index.php on line 60.

What is causing this error message?

On second thoughts, I have one more question. In general, when the pros make message boards, do they set the time to the current zone? After all, the people respnding to the threads may be living in different time zones. So, how can one set the correct time zone? For example, the time reflected in the threads started by me in this Sitepoint Forum and the times I replied to the posts does not reflect the time zone that I stay in.

‘server/timezone’ is made up, you need to specify the actual timezone you’re using as your baseline.

‘user/timezone’ is also made up, you need to obtain the timezone you have on record for your user.

Application should use a single timezone baseline (you can pick anything) and use this standard throughout the application. If you need to display the time to suit the user, then use the method I posted above.

Here’s one without made up timezones. :slight_smile:


<?php
error_reporting(-1);
ini_set('display_errors', true);

$user = array(
  'name'      => 'Anthony',
  'timezone'  => 'Europe/London'
);

$config = array(
  'timezone'  => 'Indian/Maldives'
);

/* Create using servers time/timezone */
$d = new DateTime;
$d->setTimezone(new DateTimeZone($config['timezone']));
$d->setTimestamp(time());

/* Display baseline */
echo $d->format('r');
#Wed, 12 Jan 2011 14:23:56 +0500

/* Modify to now use Users time/timezone */
$d->setTimezone(new DateTimeZone($user['timezone']));

/* Display */
echo $d->format('r');
#Wed, 12 Jan 2011 09:23:56 +0000

The newbie in me is trying to understand and implement the code
as per your explanation. Can you please tell me what is wrong
with the code below: I decided to try the servers time zone and
see how it works.
I am getting an error like this -

Fatal error: Call to
undefined method DateTime::setTimestamp() in
/home/jppp/public_html/Discussion-board/index.php on line 62

 
// We need to convert the UNIX Timestamp entered into the 
database for when a thread...  
// ... is posted into a readable date, using date().  
 /* Create using servers time/timezone */
 
$d = new DateTime;
$d->setTimezone(new DateTimeZone('Asia/Dubai'));
$d->setTimestamp($r['posted']);  // Line 62
 
/* Modify to now use Users time/timezone */
 
$d->setTimezone(new DateTimeZone('Asia/Calcutta'));
/* Display */
echo $d->format('jS M Y h:i');   
 
$posted = date("jS M Y h:i",$r['posted']);  
 

That’s strange.

DateTime::setTimestamp() requires a PHP version of 5.3.0 or over, and you have that.

Let me grab a coffee and come back to it. :slight_smile:

Anthony

Are you sure that you have 5.3.0? See what the following (in an entirely separate script) says:


<?php

echo "PHP version is ", PHP_VERSION, " and DateTime::setTimestamp() ";
echo method_exists('DateTime', 'setTimestamp') ? "exists!" : "does not exist :(";

?>

I have wamp server installed on my PC and when I look for the PHP version, it shows 5.3.0. I am unable to check using the code you provided because for some reason, the local host has not been working on my PC for quite sometime. I did not spend much time trying to find out the problem as I was testing my example sites on subdomains of my personal site on the web itself and not on the local host.

Now, since I am testing the page directly on my host’s server, will it be my host’s php version which needs to be known, am I right? I am using the services of hostgator, which I presume sho not be using an old version. Should I check the version being used by hostgator?

Yes.

I checked the support portal of hostgator and this is what I found.

What software and program versions does HostGator offer?
Quick Reference
Apache 2.2.17
PHP 5.2.15 and 5.3.4
(dual environment)
Perl 5.8.8
MySQL 5.1.52
JSP Available only on dedicated and VPS
cPanel 11.28 , auto updated to latest version
GD / Image Magic 6.6.3

All shared and reseller accounts come with:
•Linux x86 CentOS 5.5 (a free version of RedHat) 32 bit Operating System
•Kernel 2.6.34.6
•Dual Xeon E5520 2.26 GHz Quad Core Processors
•Apache 2.2.x , (includes mod_rewrite and mod_security) in a SuExec environment
•eximInternet Mailer
•WHM 11.28.x
•cPanel 11.28.x
•PHP 5.2.x and 5.3.x , PHP is run as CGI (not Apache/DSO) in a suPHP environment

…but what are you actually running? 5.2.15 or 5.3.4 ?

I will check with hostgator and get back.

After using the code provided by Salathe, I found the following:

PHP version is 5.2.15 and DateTime::setTimestamp() does not exist :frowning:

I checked with hostgator and was told the following:

We give you options to use both versions of PHP. If you want to use PHP 5.2, you can use it regularly, without any changes. If you want to use PHP 5.3, you’ll need to add this code to the document roots .htaccess:

Code:
Action application/x-hg-php53 /cgi-sys/php53AddType application/x-hg-php53 .php

Now how do I go to .htaccess? I cannot see it when I go to to my FTP client’s public_html.

If the file doesn’t exist, you can create the file.

If you want to troubleshoot any .htaccess issues, the Apache Configuration forum is the place to go.

Your FTP client maybe set to hide files which start with a period (.htaccess for example), or you may not even have an .htaccess file.

Look for this setting first, or create a dummy .test file and upload that to test.

I went on a file hunt, trying and clicking various folders and files in my FTP and found a .htaccess file which contains the following code.

 
<IfModule mod_suphp.c>
 suPHP_ConfigPath /home/jppp/php.ini
 <Files php.ini>
  order allow,deny
  deny from all
 </Files>
</IfModule>

Is this the .htaccess file in which I have to add the code?
Now I have lost the file and will have to search for it again, but hopefully I will find it.

I did manage to find the .htaccess file in more than one place.
When I opened the file manager in my cpanel, I found the .htaccess file in the web Root(public_html/www) and also the Public FTP Root (public_ftp) Public FTP Root. The code is of course different in both the locations.

As of now, I have decided not to change the timezone and let the version remain as 5.2 but know that I can turn to my forum friends if I need to. Thanks to all of you, I managed to get my message board working and also learnt a lot more.