Welcome to WebmasterWorld Guest from 107.23.37.199

Forum Moderators: coopster & jatar k & phranque

Message Too Old, No Replies

Correcting for server in wrong time zone

My UK site shows the time where the server is in USA

     
12:01 pm on Aug 2, 2007 (gmt 0)

Junior Member

10+ Year Member Top Contributors Of The Month

joined:June 12, 2004
posts:125
votes: 7


Can someone help me with changing the time zone on an SSI.

I posted this question before here [webmasterworld.com...] and it was answered by perl-diver for which I thank him/her, but that thread is now closed.

I never tried to implement the code supplied until now because I moved the site to a UK host so the time showed was correct. Now my hosting company has changed to servers in the EDT zone and the times are all wrong again.

I want to show the correct time in the UK (currently BST)not the time at the person viewing the site's location.

I currently have these includes on the page footers which work but give the time at the server.
Example:


<p><!--#config timefmt="%A, %d %B %Y %H:%M %Z" -->
<!--#echo var="DATE_LOCAL" -->.&nbsp;&nbsp;
&copy; 2007 Euroflex Products Limited.&nbsp;&nbsp;
Last modified <!--#config timefmt="%d %B %Y" --><!--#flastmod file="how-to-clean-decking.shtml" -->.</p>

Following perl-diver's advice I ftp'd a file called "date.cgi" to the CGI-Bin on the server (in ASCII format). That file contained only the following code:


#!/usr/bin/perl
$date = scalar localtime(time+18000);
print "Content-type: text/html\n\n";
print $date;
exit(0);

I then changed the include on the page as follows:


<p><!--#config timefmt="%A, %d %B %Y %H:%M %Z" -->
<!--#include virtual="../cgi-bin/date.cgi" -->.&nbsp;&nbsp;
&copy; 2007 Euroflex Products Limited.&nbsp;&nbsp;
Last modified <!--#config timefmt="%d %B %Y" --><!--#flastmod file="how-to-clean-decking.shtml" -->.</p>

ON the server the cgi-bin folder is on the same level as the folder "public" which contains all the xhtml files.

I just get the following message


[an error occurred while processing this directive]

Can someone please tell me what I'm doing wrong, I suspect it's to do with the path inside the include, I've tried a few variations and none work so far.

5:06 am on Aug 3, 2007 (gmt 0)

Preferred Member

10+ Year Member

joined:Jan 5, 2006
posts:536
votes: 0


did you give the date.cgi script execute permissions (if necessary)? Is the path to perl line correct?

#!/usr/bin/perl

try uploading the script in ASCII (text) mode if you uploaded in binary mode last time.

BTW, perl_diver = him ;)

11:35 am on Aug 3, 2007 (gmt 0)

Junior Member

10+ Year Member Top Contributors Of The Month

joined:June 12, 2004
posts:125
votes: 7


Thanks for replying.

There is no folder called "perl" in the cgi bin I put the script directly in there.

I've just tried the following paths, none of which made any difference.


#!/usr/bin/
#!/usr/bin
#!/usr/cgi-bin

The cgi-bin is on the same level as the folder "public" which contains the website, all the pages with the SSI are in the public folder not sub-folders.

These are the two SSI's I am using.


<!--#config timefmt="%A, %d %B %Y %H:%M %Z" --><!--#include virtual="../cgi-bin/date.cgi" -->

I did upload in ASCII format.

I don't know what execute permissions are, is this something the host can do for me? I can't find anything in their (somewhat limited) control panel. I will get in touch with the host, and find out.

I think I need to educate myself a bit more on this, can you recommend a good book and / or website covering perl and cgi for the absolute beginner?

1:09 pm on Aug 3, 2007 (gmt 0)

Junior Member

10+ Year Member Top Contributors Of The Month

joined:June 12, 2004
posts:125
votes: 7


OK,

My Host was as much use as a chocolate teapot - the helpdesk knew less than I did and that's saying something.

I've worked out how to set permissions using chmod through my ftp client, and set the paths as your original code. It now works but I get the date in the wrong format.

I assume that the other SSI doesn't affect the format of the date as it did on the previous code I was using.

Can you give me the extra code to format the date as follows:
Friday, 03 August 2007 13:53

The script currently gives me:
Fri Aug 3 13:53:55 2007

I've tried adding

format "%A, %d %B %Y %H:%M %Z";

or
print "%A, %d %B %Y %H:%M %Z";

with and without the quotes, but nothing happens.

many thanks.

[edited by: Old_Honky at 1:10 pm (utc) on Aug. 3, 2007]

5:42 pm on Aug 3, 2007 (gmt 0)

Preferred Member

10+ Year Member

joined:Jan 5, 2006
posts:536
votes: 0


Correct, the other SSI tag will have no affect on your perl script. Use the POSIX module in the perl script and strftime() function to format the time however you want: the format you have looks like POSIX formatting so should work:


#!/usr/bin/perl
use POSIX qw /strftime/;
use strict;
print "Content-type: text/html\n\n";
my $date = strftime("%A, %d %B %Y %H:%M %Z", localtime(time+18000));
print $date;
exit(0);

support for the time zone (%Z) is spotty. The return value can be (for example)

PST
Pacific Daylight Time
or nothing

5:54 pm on Aug 3, 2007 (gmt 0)

Junior Member

10+ Year Member Top Contributors Of The Month

joined:June 12, 2004
posts:125
votes: 7


Thank you that is working just fine.

I tried using the "%Z" and it just gave me EDT, so I have replaced it with "UK Time" We are all one timezone anyway so when the time changes back from BST to GMT it still makes sense.

Thanks again.

6:13 pm on Aug 3, 2007 (gmt 0)

Preferred Member

10+ Year Member

joined:Jan 5, 2006
posts:536
votes: 0


You're welcome
2:37 pm on Aug 14, 2007 (gmt 0)

Junior Member

10+ Year Member

joined:Sept 19, 2005
posts:44
votes: 0


FWIW, here's a similar thread that I contributed to a couple of years ago:

[webmasterworld.com...]

The issue in the above post did not involve a server-side include, but the example Perl script I provided would work well as a server-side include.

7:46 pm on Aug 14, 2007 (gmt 0)

Preferred Member

10+ Year Member

joined:May 27, 2003
posts:503
votes: 0


> can you recommend a good book and / or website covering perl and cgi

Website: Beginner's Introduction to Perl [perl.com] at perl.com [perl.com]

Books: Learning Perl [oreilly.com], Programming Perl [oreilly.com] and CGI Programming with Perl [oreilly.com].

The last book is starting to show it's age, but is a valuable resource nonetheless, especially for those just entering the field.