Paul-D Posted June 3 Share Posted June 3 http://desmond-otoole.co.uk/testdate.php Can someone check this for me (UK) <?php error_reporting(E_ALL); ini_set('display_errors', '1'); date_default_timezone_set('Europe/London'); $t_stamp = time(); echo date("d-M-Y H:s",$t_stamp); exit; ?> I am getting 03-Jun-2024 14:29 when the time is 15:04 Quote Link to comment https://forums.phpfreaks.com/topic/321303-cant-get-the-date-and-time/ Share on other sites More sharing options...
Phi11W Posted June 3 Share Posted June 3 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. Quote Link to comment https://forums.phpfreaks.com/topic/321303-cant-get-the-date-and-time/#findComment-1626739 Share on other sites More sharing options...
Paul-D Posted June 3 Author Share Posted June 3 Just check this again and the hours minutes seems to be random. I was upgraded to php8 http://desmond-otoole.co.uk/ver.php Quote Link to comment https://forums.phpfreaks.com/topic/321303-cant-get-the-date-and-time/#findComment-1626740 Share on other sites More sharing options...
Paul-D Posted June 3 Author Share Posted June 3 (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 June 3 by Paul-D Quote Link to comment https://forums.phpfreaks.com/topic/321303-cant-get-the-date-and-time/#findComment-1626741 Share on other sites More sharing options...
Paul-D Posted June 3 Author Share Posted June 3 (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 June 3 by Paul-D Quote Link to comment https://forums.phpfreaks.com/topic/321303-cant-get-the-date-and-time/#findComment-1626743 Share on other sites More sharing options...
Barand Posted June 3 Share Posted June 3 1 hour ago, Paul-D said: echo date("d-M-Y H:s",$t_stamp); Note that you are outputting Hours:seconds and not hours:minutes! Quote Link to comment https://forums.phpfreaks.com/topic/321303-cant-get-the-date-and-time/#findComment-1626747 Share on other sites More sharing options...
Paul-D Posted June 3 Author Share Posted June 3 (edited) Well spotted. have changed it to echo date("d-M-Y H:i:s",$t_stamp); . It is still wrong. It stalls. Easyspace kow there is a problem. I am paying good money for a rubbish service. Also noticed when I use my mobile phone it is difrent again. http://desmond-otoole.co.uk/testdate.php Edited June 3 by Paul-D Quote Link to comment https://forums.phpfreaks.com/topic/321303-cant-get-the-date-and-time/#findComment-1626750 Share on other sites More sharing options...
Paul-D Posted June 4 Author Share Posted June 4 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." Quote Link to comment https://forums.phpfreaks.com/topic/321303-cant-get-the-date-and-time/#findComment-1626825 Share on other sites More sharing options...
mac_gyver Posted June 4 Share Posted June 4 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. Quote Link to comment https://forums.phpfreaks.com/topic/321303-cant-get-the-date-and-time/#findComment-1626827 Share on other sites More sharing options...
Paul-D Posted June 4 Author Share Posted June 4 (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 June 4 by Paul-D Quote Link to comment https://forums.phpfreaks.com/topic/321303-cant-get-the-date-and-time/#findComment-1626830 Share on other sites More sharing options...
Barand Posted June 4 Share Posted June 4 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 Quote Link to comment https://forums.phpfreaks.com/topic/321303-cant-get-the-date-and-time/#findComment-1626864 Share on other sites More sharing options...
gizmola Posted June 4 Share Posted June 4 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. Quote Link to comment https://forums.phpfreaks.com/topic/321303-cant-get-the-date-and-time/#findComment-1626871 Share on other sites More sharing options...
Paul-D Posted June 4 Author Share Posted June 4 I only put BST to show what it represented. I have inspected the code and got this... Don't know where I am supposed to be lookimg. Quote Link to comment https://forums.phpfreaks.com/topic/321303-cant-get-the-date-and-time/#findComment-1626874 Share on other sites More sharing options...
mac_gyver Posted June 4 Share Posted June 4 22 minutes ago, Paul-D said: Don't know where I am supposed to be lookimg. 1 hour ago, Barand said: Click on one of the rows to view its headers how about clicking on the testdate.php row? Quote Link to comment https://forums.phpfreaks.com/topic/321303-cant-get-the-date-and-time/#findComment-1626877 Share on other sites More sharing options...
Solution gizmola Posted June 5 Solution Share Posted June 5 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. Quote Link to comment https://forums.phpfreaks.com/topic/321303-cant-get-the-date-and-time/#findComment-1626901 Share on other sites More sharing options...
Paul-D Posted June 8 Author Share Posted June 8 Thanks gizmola Quote Link to comment https://forums.phpfreaks.com/topic/321303-cant-get-the-date-and-time/#findComment-1627259 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.