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" -->.
© 2007 Euroflex Products Limited.
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" -->.
© 2007 Euroflex Products Limited.
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.
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
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?
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"; print "%A, %d %B %Y %H:%M %Z"; many thanks.
[edited by: Old_Honky at 1:10 pm (utc) on Aug. 3, 2007]
#!/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
[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.
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.