Jump to content

can't get the date and time


Go to solution Solved by gizmola,

Recommended Posts

What time does your hosting server (i.e. computer) think it is?   
   That's what the time() function returns and if the clock on your server has "wandered" a bit, you'll get that "wandered" value. 
   If it was out by exactly an hour, either way, I'd be thinking Timezone issues instead. 

Do you have a working NTP service running on your computer? 
   That should keep your clock properly synchronised with the rest of the world. 

Regards, 
   Phill W. 

 

Link to comment
Share on other sites

Posted (edited)

I pay a company easyspace to host my website 

I am now getting 03-Jun-2024 15:15 when it is 15:47

it was 45 minutes out now it is 32 minutes ahead. It is random. 3 minutes later it still shows 15:15

It's not the code is it? Looks fine to me.

 Just want to make sure before I contact them.  Don't understand NTP service but this is a home computer and my windows clock is correct. Is it wrong with you?

Edited by Paul-D
Link to comment
Share on other sites

Posted (edited)

Just spoke to easyspace and  am told that the server I am on has randome times. Has anyone heard of this bisare setup. We rely on that time when entering information into a database.

Edited by Paul-D
Link to comment
Share on other sites

Can someone help me with a reply from easyspace as it is confusing. [disabling varnish caching]

"Our senior administration team have reviewed the server/time issue as requested.

They have advised that the issue is a caching problem and that the coding being used would need to be set up to bypass the caching.
Alternatively, they have suggested disabling varnish caching for further testing. This can be done by our technical team if you wish to test this."

 

 

 

Link to comment
Share on other sites

the main point of server-side scripting languages, such as php, is that they dynamically produced web pages, that can have content that changes on each page request, such as displaying the current date/time. if you have web hosting that provides server-side scripting, the web server should already be configured to cause .php pages to not be cached in the browser/client (this is accomplished by outputting headers in each response that tells the browser/client to not cache the page - you can look at the response headers in the browser's developer tools, network tab, to see what is being sent), or not on the server when the content on a page changes.

the varnish cache should (already) be configured to detect when the content of a requested page changes (this is accomplished by hashing the web page being served and looking for a change in the hash value) and serve the new content, not stale previously cached content. if the varnish cache is only configured to update the cache based on a timeout, it is configured incorrectly for use with server-side scripting languages.

Link to comment
Share on other sites

Posted (edited)

Canm you tell me how I do this...

you can look at the response headers in the browser's developer tools

Also I have added HTML to the test page to invoke no cashing. Can someone check this also. I have set it to a 10 second refresh...

	<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
date_default_timezone_set('Europe/London');
$t_stamp = time();
$Nice  = date("d-M-Y H:i:s",$t_stamp);
?>
	<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Date Test</title>
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<META http-equiv="imagetoolbar" CONTENT="no">
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate"> 
<meta http-equiv="Pragma" content="no-cache"> 
<meta http-equiv="Expires" content="0">
<meta http-equiv="refresh" content="10">
<link rel="stylesheet" href="stylesheets/Library.css" type="text/css">
<link rel="stylesheet" href="stylesheets/LibraryMenu.css" type="text/css">
</head>
	<body>
<H2>This is done with no browser cashing.</H2>
Today is <?=$Nice;?> BST.
</body>
</html>
	

Also. I lot's of websites have a timeout forcing people to log in again. How can this be done if it is cashed or is it done another way? I do it by refreshing and getting the time.

They also said the coding being used would need to be set up to bypass the caching. and I am doing this.

 

Edited by Paul-D
Link to comment
Share on other sites

5 hours ago, Paul-D said:

you can look at the response headers in the browser's developer tools

  • Open your browser's develop tools.
  • Click on "Network" tab
  • Click on one of the rows to view its headers

FYI, when using date(), the default time is the current time, so this will suffice...

<?= date("d-M-Y H:i:s") ?> BST

 

Link to comment
Share on other sites

Pretty much all servers utilize UTC.  If they don't, that is ... well, "non standard" and ill advised, yet people who run their own servers, will choose to set their server up to a local timezone frequently, or use a function like "date_default_timezone_set('Europe/London');" which is ill advised in my considered opinion.

With a server set to UTC, Data is stored as UTC and defaults will be UTC, since database types in general don't have a timezone component, and rely on the server.

I'm not sure what your code is doing,  but it should rely on the intrinsic database types, which in turn will rely on the server's time.

Once you know that everything is UTC, you can then transform any time to show it in the preferred timezone.  PHP DateTime objects are sophisticated and fully capable of reliably and easily converting from one timezone to another, or taking a datetime and displaying it in the Timezone that is preferred for the end user.  Since you are wanting  London, it's already only +1 hours from UTC.

Link to comment
Share on other sites

  • Solution

Based on what your ISP stated to you, they have a Varnish Cache server in between "clients" and your server.

The cache control headers you are setting have no effect on the varnish server.  They have configured it to cache your content for some period of time.

You can learn a bit more about varnish by reading about it.  Keep in mind that this is their cache server, likely to reduced overall traffic to their hosts, and seems not to be something they advertise, which is a bit shady, but such is the way of shared hosting companies.

So when they asked you if you wanted to turn it off, at least for the purposes of this  exercise the answer is "YES".

This is the reason you are seeing the behavior you are seeing.  The requests are going to the server, the Varnish cache server is intercepting those requests and serving a cached version of your actual response for some period of time.  Once the setting expires, you see a new page.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.