I mostly need to do a specific thing, get a file to
display its last modified date and time inside itself.
I used to use ssi for this, but I moved to a new Web host and they
seem to have their server time zone set as the only time zone I can
display, and they are far away from me, so in ssi I get a date and
time for a file modification time that's many hours off.
On 29/06/2021 16.30, Not_even_a_newbie@example.net wrote:
I mostly need to do a specific thing, get a file to
display its last modified date and time inside itself.
I used to use ssi for this, but I moved to a new Web host and they
seem to have their server time zone set as the only time zone I can
display, and they are far away from me, so in ssi I get a date and
time for a file modification time that's many hours off.
I'm assuming you got the PHP code to work to show the date (even if it's
the wrong timezone for you).
If you have stored the date in a variable $lastmodified then you could
use the following code to adjust it:
$date = date_create($lastmodified, timezone_open('Pacific/Nauru'));
echo date_format($date, 'Y-m-d H:i:sP');
Just use a valid timezone name to replace the Pacific/Nauru. Keep in
mind that the time may look off for other users who do not live in the >timezone you want to display.
For more information about datetime and timezone check the following
page at php.net:
https://www.php.net/manual/en/datetime.settimezone.php
This does what I want, but only as a .PHP file. How do I get it into a
file named foo.html so I can have foo.html declare when it was last
modified?
<?php
$file = $_SERVER["SCRIPT_NAME"];
$break = Explode('/', $file);
$pfile = $break[count($break) - 1];
//echo $pfile;
echo "This file was last modified on: " .date("Y-m-d
H:m",filemtime($pfile));
I feel as if I'm almost there.
This does what I want, but only as a .PHP file. How do I get it into a
file named foo.html so I can have foo.html declare when it was last
modified?
<?php
$file = $_SERVER["SCRIPT_NAME"];
$break = Explode('/', $file);
$pfile = $break[count($break) - 1];
//echo $pfile;
echo "This file was last modified on: " .date("Y-m-d
H:m",filemtime($pfile));
I feel as if I'm almost there.
On 30/06/2021 14.08, Not_even_a_newbie@example.net wrote:
This does what I want, but only as a .PHP file. How do I get it into a
file named foo.html so I can have foo.html declare when it was last
modified?
<?php
$file = $_SERVER["SCRIPT_NAME"];
$break = Explode('/', $file);
$pfile = $break[count($break) - 1];
//echo $pfile;
echo "This file was last modified on: " .date("Y-m-d
H:m",filemtime($pfile));
I feel as if I'm almost there.
I won't comment on the code as Arno already done that, there is two
options, I would say one option is not up to you, so in reality you have
only one option (the last one)
1. Make the webserver to send .html files to tne php engine as it does
with the .php files.
2. Rename the .html file to .php
Not_even_a_newbie@example.net:
This does what I want, but only as a .PHP file. How do I get it into a
file named foo.html so I can have foo.html declare when it was last
modified?
<?php
$file = $_SERVER["SCRIPT_NAME"];
$break = Explode('/', $file);
$pfile = $break[count($break) - 1];
Why this?
//echo $pfile;
echo "This file was last modified on: " .date("Y-m-d
H:m",filemtime($pfile));
I feel as if I'm almost there.
Much simpler:
<?php
echo "This file was last modified on: ";
echo date("Y-m-d H:m",filemtime($_SERVER["SCRIPT_FILENAME"]));
Also see:
<https://www.php.net/manual/en/reserved.variables.server.php>
"'SCRIPT_FILENAME'
The absolute pathname of the currently executing script."
I don't even know if I'm up to the level of being a newbie at this
point. I mostly need to do a specific thing, get a html file to
display its last modified date and time inside itself.
I'm not sure a book is going to be that useful, but maybe a Web site
could be. I'd need one that really is basic.
I've found a Web page or two, but they seem to assume that I know more
than I do because I can't get the code snippets I've found on those
Web pages to work.
I used to use ssi for this, but I moved to a new Web host and they
seem to have their server time zone set as the only time zone I can
display, and they are far away from me, so in ssi I get a date and
time for a file modification time that's many hours off. I'm hoping
that php will solve my problem. Thanks in advance.
On Wed, 30 Jun 2021 16:24:38 +0200, "J.O. Aho" <user@example.net>
wrote:
On 30/06/2021 14.08, Not_even_a_newbie@example.net wrote:
This does what I want, but only as a .PHP file. How do I get it into a
file named foo.html so I can have foo.html declare when it was last
modified?
<?php
$file = $_SERVER["SCRIPT_NAME"];
$break = Explode('/', $file);
$pfile = $break[count($break) - 1];
//echo $pfile;
echo "This file was last modified on: " .date("Y-m-d
H:m",filemtime($pfile));
I feel as if I'm almost there.
I won't comment on the code as Arno already done that, there is two
options, I would say one option is not up to you, so in reality you have
only one option (the last one)
1. Make the webserver to send .html files to tne php engine as it does
with the .php files.
2. Rename the .html file to .php
Uh oh. But I'm reading that I can embed php into a html file. Isn't
that possible?
On 30/06/2021 19.49, Not_even_a_newbie@example.net wrote:
On Wed, 30 Jun 2021 16:24:38 +0200, "J.O. Aho" <user@example.net>
wrote:
On 30/06/2021 14.08, Not_even_a_newbie@example.net wrote:
This does what I want, but only as a .PHP file. How do I get it into a >>>> file named foo.html so I can have foo.html declare when it was last
modified?
<?php
$file = $_SERVER["SCRIPT_NAME"];
$break = Explode('/', $file);
$pfile = $break[count($break) - 1];
//echo $pfile;
echo "This file was last modified on: " .date("Y-m-d
H:m",filemtime($pfile));
I feel as if I'm almost there.
I won't comment on the code as Arno already done that, there is two
options, I would say one option is not up to you, so in reality you have >>> only one option (the last one)
1. Make the webserver to send .html files to tne php engine as it does
with the .php files.
2. Rename the .html file to .php
Uh oh. But I'm reading that I can embed php into a html file. Isn't
that possible?
The issue is that the web server will not treat each file it handles as
a php code, it will only look for files that ends with php, send those
to a PHP-engine which parses the file and executes the php code and then >hands back the output to the web server which then sends the output to
the end user (the visitor to your web page).
It's possible to allow .html/.htm files the same way, but then you need
the administration rights of the server, as you are using a shared
service, it means you don't have administrator privileges and those you
can't do the change.
So this leads to the only thing you can do, rename your files so that
they are called .php instead of .html/.htm.
If you don't want to rename files, then you need to look at javascript >solution for displaying last modified document time.
On Wed, 30 Jun 2021 22:23:32 +0200, "J.O. Aho" <user@example.net>
wrote:
On 30/06/2021 19.49, Not_even_a_newbie@example.net wrote:
On Wed, 30 Jun 2021 16:24:38 +0200, "J.O. Aho" <user@example.net>
wrote:
On 30/06/2021 14.08, Not_even_a_newbie@example.net wrote:
This does what I want, but only as a .PHP file. How do I get it into a >>>>> file named foo.html so I can have foo.html declare when it was last
modified?
<?php
$file = $_SERVER["SCRIPT_NAME"];
$break = Explode('/', $file);
$pfile = $break[count($break) - 1];
//echo $pfile;
echo "This file was last modified on: " .date("Y-m-d
H:m",filemtime($pfile));
I feel as if I'm almost there.
I won't comment on the code as Arno already done that, there is two
options, I would say one option is not up to you, so in reality you have >>>> only one option (the last one)
1. Make the webserver to send .html files to tne php engine as it does >>>> with the .php files.
2. Rename the .html file to .php
Uh oh. But I'm reading that I can embed php into a html file. Isn't
that possible?
The issue is that the web server will not treat each file it handles as
a php code, it will only look for files that ends with php, send those
to a PHP-engine which parses the file and executes the php code and then
hands back the output to the web server which then sends the output to
the end user (the visitor to your web page).
It's possible to allow .html/.htm files the same way, but then you need
the administration rights of the server, as you are using a shared
service, it means you don't have administrator privileges and those you
can't do the change.
Thanks for clarifying that. I don't control the server, but I've read
that those who do can allow html files to be scanned for php code.
Maybe my Web host has in fact done that. Would I be able to find some notation about that in the Web host's phpinfo.php file?
Also, some scripts seem to work in html files and some don't.
The following is the entire code for a file I named hello_1.html
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php echo '<p>Hello World</p>'; ?>
</body>
</html>
It produced the result:
"Hello World
'; ?> "
in the browser. It's obviously got a little problem in the output, but
it did produce a mostly useful output.
Attempts to get the php script I actually want to use to run in an
html file have not, so far, produced the thing the php script tries to
do or else the file doesn't produce any result at all.
So this leads to the only thing you can do, rename your files so that
they are called .php instead of .html/.htm.
Yeah, that would be a hassle, but if I can't get the php scripts to
run in html files that may be what I'll have to do. I'd need to see
how those php files would interact with the many html files they link
to.
If you don't want to rename files, then you need to look at javascript
solution for displaying last modified document time.
I whipped up a javascript to do what I want days ago, but a lot of
people keep javascript turned off, so it wouldn't work for them. I
supposed I could figure out how to get some message put in place of
the file modification date if javascript is turned off.
On Wed, 30 Jun 2021 15:09:57 +0200, Arno Welzel <usenet@arnowelzel.de>[...]
wrote:
Much simpler:
<?php
echo "This file was last modified on: ";
echo date("Y-m-d H:m",filemtime($_SERVER["SCRIPT_FILENAME"]));
Thanks for that. I've plugged this in and saved it as foo.php and I
get an odd reaction. The actual time stamp on the file is 13:22, but
the above script is telling me that the file was last modified at
13:06. I suppose that the idiots at my Web host may have screwed up
something on the server. The 13:22 time is when I created the file, so
it can't be that it's showing when it was created and not when it was modified. I'm scratching my head here.
Also see:
<https://www.php.net/manual/en/reserved.variables.server.php>
"'SCRIPT_FILENAME'
The absolute pathname of the currently executing script."
Okay, I don't understand what you mean in the piece immediately above
this. The above url seems to say that the script will just run.
On Wed, 30 Jun 2021 22:23:32 +0200, "J.O. Aho" <user@example.net>
wrote:
On 30/06/2021 19.49, Not_even_a_newbie@example.net wrote:
On Wed, 30 Jun 2021 16:24:38 +0200, "J.O. Aho" <user@example.net>
wrote:
On 30/06/2021 14.08, Not_even_a_newbie@example.net wrote:
This does what I want, but only as a .PHP file. How do I get it into a >>>>> file named foo.html so I can have foo.html declare when it was last
modified?
<?php
$file = $_SERVER["SCRIPT_NAME"];
$break = Explode('/', $file);
$pfile = $break[count($break) - 1];
//echo $pfile;
echo "This file was last modified on: " .date("Y-m-d
H:m",filemtime($pfile));
I feel as if I'm almost there.
I won't comment on the code as Arno already done that, there is two
options, I would say one option is not up to you, so in reality you have >>>> only one option (the last one)
1. Make the webserver to send .html files to tne php engine as it does >>>> with the .php files.
2. Rename the .html file to .php
Uh oh. But I'm reading that I can embed php into a html file. Isn't
that possible?
The issue is that the web server will not treat each file it handles as
a php code, it will only look for files that ends with php, send those
to a PHP-engine which parses the file and executes the php code and then
hands back the output to the web server which then sends the output to
the end user (the visitor to your web page).
It's possible to allow .html/.htm files the same way, but then you need
the administration rights of the server, as you are using a shared
service, it means you don't have administrator privileges and those you
can't do the change.
Thanks for clarifying that. I don't control the server, but I've read
that those who do can allow html files to be scanned for php code.
Maybe my Web host has in fact done that. Would I be able to find some notation about that in the Web host's phpinfo.php file?
Also, some scripts seem to work in html files and some don't.
The following is the entire code for a file I named hello_1.html
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php echo '<p>Hello World</p>'; ?>
</body>
</html>
It produced the result:
"Hello World
'; ?> "
in the browser. It's obviously got a little problem in the output, but
it did produce a mostly useful output.
On Wed, 30 Jun 2021 16:24:38 +0200, "J.O. Aho" <user@example.net>[...]
wrote:
2. Rename the .html file to .php
Uh oh. But I'm reading that I can embed php into a html file. Isn't
that possible?
Thanks for clarifying that. I don't control the server, but I've read
that those who do can allow html files to be scanned for php code.
Maybe my Web host has in fact done that. Would I be able to find some >notation about that in the Web host's phpinfo.php file?
In article <rdbmdghp8532b2sgknb9iqv6a0i6vlom8p@4ax.com>, Not_even_a_newbie@example.net says...
I don't even know if I'm up to the level of being a newbie at this
point. I mostly need to do a specific thing, get a html file to
display its last modified date and time inside itself.
I'm not sure a book is going to be that useful, but maybe a Web site
could be. I'd need one that really is basic.
I've found a Web page or two, but they seem to assume that I know more
than I do because I can't get the code snippets I've found on those
Web pages to work.
I used to use ssi for this, but I moved to a new Web host and they
seem to have their server time zone set as the only time zone I can
display, and they are far away from me, so in ssi I get a date and
time for a file modification time that's many hours off. I'm hoping
that php will solve my problem. Thanks in advance.
https://code.adonline.id.au/last-modified-date-php/
In article <4mcqdgtiqjshpeg88h50b5l97fp3qmflfu@4ax.com>,
<Not_even_a_newbie@example.net> wrote:
Thanks for clarifying that. I don't control the server, but I've read
that those who do can allow html files to be scanned for php code.
Maybe my Web host has in fact done that. Would I be able to find some >>notation about that in the Web host's phpinfo.php file?
You don't need to control the server itself; many hosts --indeed all the
good ones, I say-- allow you to redirect .html to the PHP engine one way
or another, typically from .htaccess with AddType and AddHandler
directives. Check your host's help system or file a support ticket, they >probably have a FAQ answer ready.
On Thu, 1 Jul 2021 21:36:05 -0000 (UTC), rcpj@panix.com (Pierre
Jelenc) wrote:
In article <4mcqdgtiqjshpeg88h50b5l97fp3qmflfu@4ax.com>,
<Not_even_a_newbie@example.net> wrote:
Thanks for clarifying that. I don't control the server, but I've read >>>that those who do can allow html files to be scanned for php code.
Maybe my Web host has in fact done that. Would I be able to find some >>>notation about that in the Web host's phpinfo.php file?
You don't need to control the server itself; many hosts --indeed all the >>good ones, I say-- allow you to redirect .html to the PHP engine one way
or another, typically from .htaccess with AddType and AddHandler >>directives. Check your host's help system or file a support ticket, they >>probably have a FAQ answer ready.
I have apparently gotten the server to process PHP scripts inside the
HTML file. Things is, that's kind of wasteful and may slow things
down, for me and for others. I did read on one of the many Web pages
I've been looking at over this topic that besides putting "AddType >application/x-httpd-php .html" into my .htaccess file, and making ALL
HTML files get processed for any PHP scripts, that there was also a
way to do it for a single file. I have about five files I need to do
this modification notice for.
The code for a single file that I saw was "<Files yourpage.html>
AddType application/x-httpd-php .html </Files>" where yourpage.html
was whatever that one file was named.
Does anyone know if it's possible to use that declaration, or
something like it, in the .htaccess file so that only the five HTML
files that really need to have PHP processed will get processed and
all other HTML files will not be?
Not_even_a_newbie@example.net:
On Wed, 30 Jun 2021 22:23:32 +0200, "J.O. Aho" <user@example.net>
wrote:
On 30/06/2021 19.49, Not_even_a_newbie@example.net wrote:
On Wed, 30 Jun 2021 16:24:38 +0200, "J.O. Aho" <user@example.net>
wrote:
On 30/06/2021 14.08, Not_even_a_newbie@example.net wrote:
This does what I want, but only as a .PHP file. How do I get it into a >>>>>> file named foo.html so I can have foo.html declare when it was last >>>>>> modified?
<?php
$file = $_SERVER["SCRIPT_NAME"];
$break = Explode('/', $file);
$pfile = $break[count($break) - 1];
//echo $pfile;
echo "This file was last modified on: " .date("Y-m-d
H:m",filemtime($pfile));
I feel as if I'm almost there.
I won't comment on the code as Arno already done that, there is two
options, I would say one option is not up to you, so in reality you have >>>>> only one option (the last one)
1. Make the webserver to send .html files to tne php engine as it does >>>>> with the .php files.
2. Rename the .html file to .php
Uh oh. But I'm reading that I can embed php into a html file. Isn't
that possible?
The issue is that the web server will not treat each file it handles as
a php code, it will only look for files that ends with php, send those
to a PHP-engine which parses the file and executes the php code and then >>> hands back the output to the web server which then sends the output to
the end user (the visitor to your web page).
It's possible to allow .html/.htm files the same way, but then you need
the administration rights of the server, as you are using a shared
service, it means you don't have administrator privileges and those you
can't do the change.
Thanks for clarifying that. I don't control the server, but I've read
that those who do can allow html files to be scanned for php code.
Maybe my Web host has in fact done that. Would I be able to find some
notation about that in the Web host's phpinfo.php file?
Also, some scripts seem to work in html files and some don't.
The following is the entire code for a file I named hello_1.html
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php echo '<p>Hello World</p>'; ?>
</body>
</html>
It produced the result:
"Hello World
'; ?> "
in the browser. It's obviously got a little problem in the output, but
it did produce a mostly useful output.
No. The output comes from the fact, that PHP was *not* interpreted.
The browser displays *exactly* this:
<?php echo '<p>Hello World</p>'; ?>
Just have a look at the source of the page which is displayed by the
browser.
Since <?php will treated by the browser as the beginning of a tag, it
will be omitted in the visible output. But "; ?>" is clearly left over
as the PHP code was *not* interpreted but just sent to the browser. The >result is then what you see.
If renaming everything from .html to .php you should look for a hosting >service which allows using .html with PHP as well. Technically this is
just a configuration in the webserver - however that is usually not
possible in shared hosting environments.
echo "" .date("Y-m-d H:m",filemtime($pfile));
No matter what I do I always get the same minutes.
....
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>will php run in html now?</title>
<meta http-equiv="description" content="">
<meta http-equiv="keywords" content=",">
<meta http-equiv="distribution" content="global">
<meta http-equiv="resource-type" content="document">
</head>
<body>
<h1>Am I Going To Get it Now?</h1>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</p>
<br>
<br>
Updated:
<?php
date_default_timezone_set('America/New_York');
$file = $_SERVER["SCRIPT_NAME"];
$break = Explode('/', $file);
$pfile = $break[count($break) - 1];
echo "" .date("Y-m-d H:m",filemtime($pfile));
The output of that code was:
Am I Going To Get it Now?
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Updated: 2021-07-02 18:07
....
On 2021-07-02 7:36 p.m., Not_even_a_newbie@example.net wrote:
echo "" .date("Y-m-d H:m",filemtime($pfile));
No matter what I do I always get the same minutes.
You're not showing minutes at all. Lower case m is month number (as you
used in the date).
You probably want H:i for hour and minutes; hour
and month is an odd pairing!
https://www.php.net/manual/en/datetime.format.php
<?php
date_default_timezone_set('America/New_York');
$file = $_SERVER["SCRIPT_NAME"];
$break = Explode('/', $file);
Not_even_a_newbie@example.net:
[...]
<?php
date_default_timezone_set('America/New_York');
$file = $_SERVER["SCRIPT_NAME"];
$break = Explode('/', $file);
The function name is "explode()" in lower case and not "Explode()". Even
if PHP accepts the upper case version as well you should use the correct
case to avoid problems with future updates.
Also see: <https://www.php.net/manual/en/function.explode.php>
I don't even know if I'm up to the level of being a newbie at thispoint. I mostly need to do a specific thing, get a html file todisplay its last modified date and time inside itself.I'm not sure a book is going to be that useful, but maybe a Websitecould be. I'd need one that really is basic.I've found a Web page or two, but they seem to assume that I know morethan I do because I can't get the code snippets I've found on thoseWeb pages to work.I used to use ssi for this, but I moved to a new
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 349 |
Nodes: | 16 (2 / 14) |
Uptime: | 120:48:12 |
Calls: | 7,612 |
Files: | 12,789 |
Messages: | 5,684,234 |