Welcome to the JaguarPC Community
JaguarPC
Sales: (888) 338-5261
Support: (888)-551-3050
Results 1 to 13 of 13

This is a discussion on Server Side Includes problem in the Shared & Semi-Dedicated forum
Hi! Is there any way to configurate the SSI directive DATE_GMT in order to display the current date and time for a local user? That ...

  1. #1
    JPC Member
    Join Date
    May 2003
    Posts
    28

    Server Side Includes problem

    Hi!

    Is there any way to configurate the SSI directive DATE_GMT in order to display the current date and time for a local user?

    That is, the problem is that we have some clients in Europe and from different locations and in several countries they are using daylight time saving clocks. When filling a web form the date and time is stamped on it, so, how to achieve this in order the time and date are displayed as their local time zone?

    I have tested DATE_LOCAL, but shows the server's time and date (located in texas (U.S.)

    Also have tested DATE_GMT but this do not match the real date and time for some countries that use GMT+1 or GMT+2, and so on.

    Any idea? Thanks.

  2. #2
    Community Leader jason's Avatar
    Join Date
    Sep 2001
    Location
    Rochester, NY
    Posts
    6,003
    SSI is a server-side include. The server knows two things: the date and time of where it is (DATE_LOCAL) and the equivalent GMT (DATE_GMT). The was an SSI works is, when a page is requested, the server opens it up and scans for SSI tags. It replaces those tags with the requested info. The SSI engine has no way of figuring out where the user is located and there is no way to get the end user's time through SSI, only the server's.

    If the end user's time is really important, consider one of these:

    Use JavaScript to get the date and time. JavaScript is run client side, so it will be getting its time from whatever the user's clock is set to (which may be incorrect, BTW). This won't work if the user has JavaScript disabled, however.

    -or-

    Use the server's time (either local or GMT) and then use a script to interpolate their time based on their location. This will be considerably harder to do than the JavaScript method, but it should always work.
    Jason Pitoniak
    Interbrite Communications
    www.interbrite.com www.kodiakskorner.com

  3. #3
    Jag Veteran
    Join Date
    Sep 2002
    Posts
    650
    Originally posted by jason
    Use the server's time (either local or GMT) and then use a script to interpolate their time based on their location. This will be considerably harder to do than the JavaScript method, but it should always work.
    Do you suggest to get user location based on IP address?
    Because any other method still seems to require client-side script.

  4. #4
    Just Walking...
    Join Date
    Oct 2002
    Location
    England
    Posts
    436
    Or add an extra field to the form, a drop-down list of countries from which it should then be possible to calculate the local time. However even that would require a sophisticated script that had encyclopaedic information on when and if daylight savings is applied in each country. If you have the inclination and time this would be the most robust way to do it.

    As Jason said the only other way is Javascript but if you think it important that this timestamping be correct then javascript is just too flaky and flawed.

  5. #5
    JPC Member
    Join Date
    May 2003
    Posts
    28
    Hello people!

    Thanks for your help. As you stated, Javascript is not a good idea (can be desactivated and misconfigured by the user). Time is very important and must be accurate, so it cannot depend on the user's computer configuration. So that I thank about using SSI.



    I'm afraid I have to implement a bit of programming (maybe a perl script) in order to achieve this.

    Another one more question... Could I get the right date / time by using PHP? I think the problem is the same, dont'n you?



    Regards

  6. #6
    Community Leader jason's Avatar
    Join Date
    Sep 2001
    Location
    Rochester, NY
    Posts
    6,003
    Yes, the problem would be the same with PHP because just like SSI, PHP is server-side scripting. Like SSI, PHP knows the server's time and can use that to calculate GMT, but the PHP script has no way of knowing where your visitor is coming from without you somehow giving the script that information.

    --Jason
    Jason Pitoniak
    Interbrite Communications
    www.interbrite.com www.kodiakskorner.com

  7. #7
    Jag Veteran
    Join Date
    Sep 2002
    Posts
    650
    Just an idea, but Flash might be an easier option than Javascript: it doesn't depend so much on browser version and security settings.

  8. #8
    JPC Member
    Join Date
    May 2003
    Posts
    28
    Hello again,

    Thank you very much for your help. I took a look into Hotscripts.com (a very good site for programming resources) and I have solved this issue with the following script:

    http://www.surf7.net/download/datetime.shtml

    I have fit the source code to my needs and I'm getting the right time... only one time zone, but it's O.K.

    Just an idea for Jaguar / Aletia hosting, it would be great if under CPanel the users could choose the server time zone in order to get Apache web server to fit their needs. Many people hosted with Jaguar / Aletia come from diverese countries outside U.S. and this feature would be very appreciated.

    Anyway, thanks again for your ideas. Glad to be here.


  9. #9
    Jag Veteran
    Join Date
    Sep 2002
    Posts
    650
    Arot,
    Server time zone is a server-wide setting and it has nothing to do with Apache, so unless you get a dedicated server you are stuck with it

    But if you think that the script you mentioned above is good for you, then just use its OFFSET variable to "convert" server's localtime to your localtime.
    2 notes about that script, however:
    1. I don't think it handles negative offset values correctly.
    2. It doesn't address daylight saving issue.

  10. #10
    JPC Member
    Join Date
    May 2003
    Posts
    28
    Originally posted by gerilya
    Arot,
    Server time zone is a server-wide setting and it has nothing to do with Apache, so unless you get a dedicated server you are stuck with it

    But if you think that the script you mentioned above is good for you, then just use its OFFSET variable to "convert" server's localtime to your localtime.
    2 notes about that script, however:
    1. I don't think it handles negative offset values correctly.
    2. It doesn't address daylight saving issue.
    O.K. I understand. It's not a good idea to change this variable with a global scope. I thought it can be done "selectively" in virtual hosting.



    Regarding the notes about the script:

    1) Where is the problem with negative offset? Sorry, I'm not very good at programming... In any case, I am using a positive value, but could you explain a bit more?

    2) Yes. But it's the best I have found. I will have to change the offset value when it comes the summer time.

  11. #11
    Jag Veteran
    Join Date
    Sep 2002
    Posts
    650
    Here is how the script looks like:

    #!/usr/local/bin/perl

    ######################################## ################
    # DateTime 1.1 #
    ######################################## ################
    # Author : Benjamin Leow #
    # Released date : 11 September 2002 #
    # E-mail : ben@surf7.net #
    # Website : http://www.surf7.net #
    ######################################## ################
    # Installation Guide #
    # #
    # - Change the above's path to Perl if it doesn't #
    # match your server's configuration #
    # - Change the $offset value accordingly #
    # - Upload this script to your server in ASCII mode. #
    # - CHMOD this script to 755 #
    # - Call this script with SSI #
    # #
    # Example, #
    # #
    # <!--#exec cgi="cgi-bin/datetime.pl"--> #
    # #
    ######################################## ################

    # Offset in hour. Sorry, you have to do your own calculation.
    # Just a simple mathematic calculation...

    my $offset = 0;

    ######################################
    # No configurations are needed below #
    ######################################

    ($sec,$min,$hour,$mday,$mon,$year,$wday, $yday,$isdst) = localtime(time);

    $year += 1900;
    $hour=$hour+$offset;
    if ($hour >= 24) {
    $hour = $hour - 24;
    $mday = $mday + 1;
    }
    if ($hour >= 12) {
    if ($hour > 12){
    $hour = $hour - 12;
    }
    $ampm = "pm";
    }
    else { $ampm = "am"; }

    if ($sec < 10) { $sec = "0$sec"; }
    if ($min < 10) { $min = "0$min"; }
    if ($mon < 10) { $mon = "0$mon"; }
    if ($mday < 10) { $mday = "0$mday"; }
    $month = ($mon + 1);
    @months = ("Jan","Feb","Mar","Apr","May","Jun","Ju l","Aug","Sep","Oct","Nov","Dec");
    my $date = "$mday-$months[$mon]-$year";
    chop($date) if ($date =~ /\n$/);

    my $datetime = "$date $hour:$min $ampm";

    print "Content-type: text/html\n\n";
    print "$datetime";
    exit;

  12. #12
    Jag Veteran
    Join Date
    Sep 2002
    Posts
    650
    Now, try using offset = -1, for example and see what happens. This is what I call a problem with negative offset .

    I would also guess that this script has another bug, which is only noticable at the end of the month for a few hours.

    I would assume that the following should fix that, but I don't have a time to make tests right now:

    Replace
    ($sec,$min,$hour,$mday,$mon,$year,$wday, $yday, $isdst) = localtime(time);

    $year += 1900;
    $hour=$hour+$offset;
    if ($hour >= 24) {
    $hour = $hour - 24;
    $mday = $mday + 1;
    }
    with

    ($sec,$min,$hour,$mday,$mon,$year,$wday, $yday, $isdst) = localtime(time + 3600*$offset);
    $year += 1900;
    Last edited by gerilya; 01-26-2004 at 12:06 PM.

  13. #13
    JPC Member
    Join Date
    May 2003
    Posts
    28
    Thank you, gerilya!



    I'll give it a try.

    Greetings

    Well, I have tested a bit more the script and if I set the offset variable to "-1" the output (I think) is O.K. It's like DATE_LOCAL plus or minus the offset value.

    The script gets the localtime from the server (Dallas, TX, U.S.) as "base time" and then operates depending that value. If the offset for one european region is +6 (daylight saving time included), then the only I have to change is that value.

    I'm aware this does not fit for some countries neither daylight saving time, but now fits my needs.
    Last edited by arot; 01-27-2004 at 01:11 AM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •