Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

404 error

7 views
Skip to first unread message

Ed Mullen

unread,
Apr 22, 2014, 12:41:29 PM4/22/14
to
I have two sites on different hosts.

Both use identical code to display a "last modified" message. The code
is in a standard footer which is included (via PHP) on ever site page.

I just noticed something odd. At my site <http://edmullen.net> it works
just fine. The first link below shows a standard page with the footer
message. The second will produce an error page since the link doesn't
exist on the site. On the error page the date info is simply not displayed.

<http://edmullen.net/index.php>

<http://edmullen.net/bogus.php>

Fine so far. The other site has different results.

<http://guitarsnotguns.org/>

<http://guitarsnotguns.org/rot.php>

Notice the error message and incorrect date in the footer.

I'm guessing it's a server configuration issue. Any thoughts?

BTW, here's the PHP I use on both sites:

<?php
$current_file_name = ($_SERVER['REQUEST_URI']);
$current_path = ($_SERVER['DOCUMENT_ROOT']);
$full_name = $current_path.$current_file_name;
$last_modified = filemtime($full_name);
print("This page last changed: ");
print(date("F j, Y - h:i A", $last_modified));
?>

Thanks.

--
Ed Mullen
http://edmullen.net/
A fool-proof method for sculpting an elephant: First, get a huge block
of marble; then chip away everything that doesn't look like an elephant.

Jerry Stuckle

unread,
Apr 22, 2014, 12:58:18 PM4/22/14
to
If the file doesn't exist, how can you get its time?

It looks like you're including your footer in the failing page, but not
in the working one. This is not a PHP issue.


--
==================
Remove the "x" from my email address
Jerry Stuckle
jstu...@attglobal.net
==================

Ed Mullen

unread,
Apr 22, 2014, 1:25:23 PM4/22/14
to
Agreed. Not expecting to.

> It looks like you're including your footer in the failing page, but not
> in the working one. This is not a PHP issue.
>
>

The footer is in the two good links above. The failing pages above do
not exist: They're links to a non-existant file. Hence the 404 result.

What I'm asking about is how the two hosts' servers handle it. The
first displays the custom 404 page WITHOUT showing the date in the
footer. No idea why.

The second host shows the 404 page but throws an error where the "date
modified" info should be. Obviously

--
Ed Mullen
http://edmullen.net/
Zen master to hot dog vendor: "Make me one with everything."

Ed Mullen

unread,
Apr 22, 2014, 1:32:42 PM4/22/14
to
Oops. Hit send too fast.

I was going to say that obviously there is something different about the
servers set up.

I agree, it's probably not a PHP issue. Just thought the smart folks
here might have an idea.


--
Ed Mullen
http://edmullen.net/
"A conscience is like a boat or a car. If you feel you need one, rent
it." - J.R. Ewing

Jerry Stuckle

unread,
Apr 22, 2014, 2:35:21 PM4/22/14
to
Then check in a server-related newsgroup. This isn't a PHP problem.

Lew Pitcher

unread,
Apr 22, 2014, 2:42:20 PM4/22/14
to
On Tuesday 22 April 2014 13:32, in comp.lang.php, "Ed Mullen"
My (semi-educated) guess:

On edmullen.net, your php.ini file sets the error_reporting value to
E_ERROR, while on guitarsnotguns.org, the php.ini file sets the
error_reporting value to E_WARNING

E_ERROR settings will halt execution of the php script; if
filemtime($full_name) encounters a "file not found" error, the script
stops, and does not execute the subsequent printf() statements.


E_WARNING settings will not halt execution of the php script; if
filemtime($full_name) encounters a "file not found" error, the script
continues and tries execute the subsequent printf() statements.

Compare the php.ini settings (both explicit and implicit-default) from both
sites, especially the error_reporting and display_errors values, to see how
you've set PHP to handle errors.

HTH
--
Lew Pitcher
"In Skills, We Trust"
PGP public key available upon request

Jerry Stuckle

unread,
Apr 22, 2014, 2:56:20 PM4/22/14
to
Incorrect. An error will ALWAYS stop execution of the script, no matter
what the error_reporting value is. And a warning will NEVER stop
execution of the script, no matter what the error_reporting value is.

All this does is control what level of message is reported; it does not
affect execution in any way.

Thomas 'PointedEars' Lahn

unread,
Apr 22, 2014, 5:26:13 PM4/22/14
to
Ed Mullen wrote:

> <http://edmullen.net/index.php>
> <http://edmullen.net/bogus.php>
>
> Fine so far. The other site has different results.
> […]
> http://guitarsnotguns.org/rot.php
>
> Notice the error message and incorrect date in the footer.

It is not an error message, it is a *warning*.

> I'm guessing it's a server configuration issue. Any thoughts?
>
> BTW, here's the PHP I use on both sites:
>
> <?php
> $current_file_name = ($_SERVER['REQUEST_URI']);
> $current_path = ($_SERVER['DOCUMENT_ROOT']);

It is pointless and confusing for people accustomed to writing PHP code to
put the RHS into parentheses here.

> $full_name = $current_path.$current_file_name;
> $last_modified = filemtime($full_name);

Look closely at that warning. This approach is not going to work reliably
because the HTTP request URI does not need to have anything to do with the
file path of the resource. In fact, there does not even need to be a real
file for a URI, the served content could have been generated entirely by PHP
(and usually is). As a result, in those cases filemtime() returns FALSE …

> print(date("F j, Y - h:i A", $last_modified));

… which date() converts to 0 (UNIX epoch) – as it expects an int (UNIX
timestamp), not a boolean value, for the second argument – and formats that
accordingly to “December 31, 1969” (not “January 1, 1970 - 12:00 AM”
probably because of timezone issues), which is then send to stdout by
print(). (You should use “echo” instead, unless in an expression where you
need “print”’s return value. Think sh, not perl.)

,----
| $ php -r 'echo date("F, j Y - h:i A", filemtime("Slartibartfast")) .
| "\n";'
| PHP Warning: filemtime(): stat failed for Slartibartfast in Command line
| code on line 1
| PHP Stack trace:
| PHP 1. {main}() Command line code:0
| PHP 2. filemtime() Command line code:1
| January, 1 1970 - 01:00 AM
|
| $ php -v
| PHP 5.5.11-3 (cli) (built: Apr 19 2014 16:46:26)
| Copyright (c) 1997-2014 The PHP Group
| Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
| with XCache v3.1.0, Copyright (c) 2005-2013, by mOo
| with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2014, by Zend
| Technologies
| with Xdebug v2.2.4, Copyright (c) 2002-2014, by Derick Rethans
| with XCache Optimizer v3.1.0, Copyright (c) 2005-2013, by mOo
| with XCache Cacher v3.1.0, Copyright (c) 2005-2013, by mOo
| with XCache Coverager v3.1.0, Copyright (c) 2005-2013, by mOo
`----

(I am in UTC+2 now because of European Summer Time, and date.timezone is set
to “Europe/Zurich”; the latter would account for the one-hour advance.)

You might be looking for filemtime(__FILE__) instead.

<http://php.net/phpinfo>
<http://php.net/filemtime>
<http://php.net/date>
<http://php.net/print>
<http://php.net/echo>
<http://php.net/manual/en/language.constants.predefined.php>


PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann

Doug Miller

unread,
Apr 22, 2014, 6:04:49 PM4/22/14
to
Ed Mullen <ejEV...@edmullen.net> wrote in news:7f2rl4....@news.alt.net:

[...]
> <http://guitarsnotguns.org/>

What in the world are "guitar snot guns" ?

The Natural Philosopher

unread,
Apr 22, 2014, 7:11:40 PM4/22/14
to
Dont ask...



--
Ineptocracy

(in-ep-toc’-ra-cy) – a system of government where the least capable to
lead are elected by the least capable of producing, and where the
members of society least likely to sustain themselves or succeed, are
rewarded with goods and services paid for by the confiscated wealth of a
diminishing number of producers.

Ed Mullen

unread,
Apr 22, 2014, 8:22:00 PM4/22/14
to
Cute.

Guitars Not Guns.

A legal non-profit involved in a serious cause, reducing childhood gun
violence.

When you stop mocking a legitimate organization feel free to donate.

--
Ed Mullen
http://edmullen.net/
Save your breath, you'll need it to blow up your date.

Anders Wegge Keller

unread,
Apr 23, 2014, 2:56:52 AM4/23/14
to
Jerry Stuckle <jstu...@attglobal.net> writes:

> Incorrect. An error will ALWAYS stop execution of the script, no
> matter what the error_reporting value is. And a warning will NEVER
> stop execution of the script, no matter what the error_reporting value
> is.

filemtime

(PHP 4, PHP 5)
filemtime — Gets file modification time

...

Errors/Exceptions ¶

Upon failure, an E_WARNING is emitted.

--
/Wegge

Leder efter redundant peering af dk.*,linux.debian.*

Thomas 'PointedEars' Lahn

unread,
Apr 23, 2014, 7:12:48 AM4/23/14
to
Anders Wegge Keller wrote:

> Jerry Stuckle <jstu...@attglobal.net> writes:
>> Incorrect. An error will ALWAYS stop execution of the script, no
>> matter what the error_reporting value is. And a warning will NEVER
>> stop execution of the script, no matter what the error_reporting value
>> is.
>
> filemtime
>
> (PHP 4, PHP 5)
> filemtime — Gets file modification time
>
> ...
>
> Errors/Exceptions ¶
>
> Upon failure, an E_WARNING is emitted.

What are you getting at?


PointedEars
--
When all you know is jQuery, every problem looks $(olvable).

Anders Wegge Keller

unread,
Apr 23, 2014, 7:23:57 AM4/23/14
to
Thomas 'PointedEars' Lahn <Point...@web.de> writes:

> Anders Wegge Keller wrote:
>
> > Jerry Stuckle <jstu...@attglobal.net> writes:
> >> Incorrect. An error will ALWAYS stop execution of the script, no
> >> matter what the error_reporting value is. And a warning will NEVER
> >> stop execution of the script, no matter what the error_reporting value
> >> is.
> >
> > filemtime
> >
> > (PHP 4, PHP 5)
> > filemtime — Gets file modification time
> >
> > ...
> >
> > Errors/Exceptions ¶
> >
> > Upon failure, an E_WARNING is emitted.
>
> What are you getting at?

Pointing out the futility of discussing E_ERROR in this case.

Thomas 'PointedEars' Lahn

unread,
Apr 23, 2014, 7:36:00 AM4/23/14
to
But the point made here was that error_reporting settings do not influence
php’s behavior with regard to the program flow per se, only which
errors/warnings/notices will be reported by php. The opposite had been
assumed by Lew Pitcher.

One should not misconstrue the generic format of the documentation or the
identifiers or values of error constants as proof that errors, warnings and
notices would be *functionally* the same.

Jerry Stuckle

unread,
Apr 23, 2014, 8:08:48 AM4/23/14
to
On 4/23/2014 2:56 AM, Anders Wegge Keller wrote:
> Jerry Stuckle <jstu...@attglobal.net> writes:
>
>> Incorrect. An error will ALWAYS stop execution of the script, no
>> matter what the error_reporting value is. And a warning will NEVER
>> stop execution of the script, no matter what the error_reporting value
>> is.
>
> filemtime
>
> (PHP 4, PHP 5)
> filemtime — Gets file modification time
>
> ...
>
> Errors/Exceptions ¶
>
> Upon failure, an E_WARNING is emitted.
>

Which has absolutely nothing to do with what I said...

Jerry Stuckle

unread,
Apr 23, 2014, 8:09:23 AM4/23/14
to
So? Just trying to make yourself heard?

Christoph Michael Becker

unread,
Apr 23, 2014, 8:21:11 AM4/23/14
to
Thomas 'PointedEars' Lahn:

> Look closely at that warning. This approach is not going to work reliably
> because the HTTP request URI does not need to have anything to do with the
> file path of the resource. In fact, there does not even need to be a real
> file for a URI, the served content could have been generated entirely by PHP
> (and usually is). As a result, in those cases filemtime() returns FALSE …

ACK.

> You might be looking for filemtime(__FILE__) instead.

__FILE__ contains the filepath of the currently *included* file; in Ed's
case the following should be more appropriate:

filemtime($_SERVER['SCRIPT_NAME']);

--
Christoph M. Becker

Jerry Stuckle

unread,
Apr 23, 2014, 9:12:40 AM4/23/14
to
True - which in this case would be the footer, not the requested page.

> filemtime($_SERVER['SCRIPT_NAME']);
>

Unfortunately, this, too, may or may not have any relationship to the
file system.

Thomas 'PointedEars' Lahn

unread,
Apr 23, 2014, 9:55:57 AM4/23/14
to
Christoph Michael Becker wrote:

> Thomas 'PointedEars' Lahn:
>> You might be looking for filemtime(__FILE__) instead.
>
> __FILE__ contains the filepath of the currently *included* file; in Ed's
> case the following should be more appropriate:
>
> filemtime($_SERVER['SCRIPT_NAME']);

IBTD. Who is to tell that he did not want to modification time of an
include? As it is, the code makes no sense anyway, even with the
corrections I suggested.

I find it hard to believe that anyone is interested in the last modification
date of a script that generates error documents; I find it more probable
that one wants to output the date and time when the error document was
generated, so that the user can make the connection between the availability
of the requested resource and the date of the request. If so, filemtime()
is the wrong approach; mktime() or (better) gmmktime() should be used
instead.


PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f806at$ail$1$8300...@news.demon.co.uk>

Thomas 'PointedEars' Lahn

unread,
Apr 23, 2014, 9:56:24 AM4/23/14
to
Christoph Michael Becker wrote:

> Thomas 'PointedEars' Lahn:
>> You might be looking for filemtime(__FILE__) instead.
>
> __FILE__ contains the filepath of the currently *included* file; in Ed's
> case the following should be more appropriate:
>
> filemtime($_SERVER['SCRIPT_NAME']);

IBTD. Who is to tell that he did not want the modification time of an

Christoph Michael Becker

unread,
Apr 23, 2014, 12:00:36 PM4/23/14
to
Thomas 'PointedEars' Lahn wrote:

> Christoph Michael Becker wrote:
>
>> Thomas 'PointedEars' Lahn:
>>> You might be looking for filemtime(__FILE__) instead.
>>
>> __FILE__ contains the filepath of the currently *included* file; in Ed's
>> case the following should be more appropriate:
>>
>> filemtime($_SERVER['SCRIPT_NAME']);
>
> IBTD. Who is to tell that he did not want the modification time of an
> include? As it is, the code makes no sense anyway, even with the
> corrections I suggested.

In <news:7f2rl4....@news.alt.net> Ed Mullen wrote:

> I have two sites on different hosts.
>
> Both use identical code to display a "last modified" message. The
> code is in a standard footer which is included (via PHP) on ever site
> page.

From that and the rest of the OP I assume, that the requested PHP
resource (rot.php) is stored as a file, and the last modification date
of this file should be displayed, what doesn't seem to be unreasonable
as long as it would be modified regarding the contained HTML, only.

--
Christoph M. Becker

Ed Mullen

unread,
Apr 23, 2014, 12:39:17 PM4/23/14
to
Ed Mullen wrote:
> I have two sites on different hosts.
>
> Both use identical code to display a "last modified" message. The code
> is in a standard footer which is included (via PHP) on ever site page.
>
> I just noticed something odd. At my site <http://edmullen.net> it works
> just fine. The first link below shows a standard page with the footer
> message. The second will produce an error page since the link doesn't
> exist on the site. On the error page the date info is simply not
> displayed.

Thanks to all for the suggestions. I'll try them and see what happens.


--
Ed Mullen
http://edmullen.net/
After eating, do amphibians have to wait one hour before getting out of
the water?

Ed Mullen

unread,
Apr 23, 2014, 1:12:59 PM4/23/14
to
Indeed. When I do phpinfo on both hosts:

edmullen.net - error_reporting = 22517
guitarsnotguns.org - error_reporting = 30711

I haven't yet figured out how to get access to the php.ini file on
DreamHost, GNG's hosting service. Their documentation/help is somewhat
byzantine.

Thanks, Lew.

P.S. Googled and found that if I put this in the custom error pages as
the first line in "include" script it stops the error. The date is
still wrong but that's less annoying.

<?php error_reporting(22517); ?>



--
Ed Mullen
http://edmullen.net/
All those who believe in psychokinesis raise my hand.

Ed Mullen

unread,
Apr 23, 2014, 2:22:29 PM4/23/14
to
Ed Mullen wrote:
> Ed Mullen wrote:
>> I have two sites on different hosts.
>>
>> Both use identical code to display a "last modified" message. The code
>> is in a standard footer which is included (via PHP) on ever site page.
>>
>> I just noticed something odd. At my site <http://edmullen.net> it works
>> just fine. The first link below shows a standard page with the footer
>> message. The second will produce an error page since the link doesn't
>> exist on the site. On the error page the date info is simply not
>> displayed.
>
> Thanks to all for the suggestions. I'll try them and see what happens.
>
>

Tried various things and decided to apply the KISS method. Made a
separate footer text file for the custom error files without the "last
modified" code in it.

--
Ed Mullen
http://edmullen.net/
Unable to close TROUSER.ZIP! - Replace floppy and retry (Y/N)?

Jerry Stuckle

unread,
Apr 23, 2014, 2:50:56 PM4/23/14
to
If you INSIST on using this footer, good programming requires you to
check for the presence of the file (see file_exists) before calling
filemtime(). If it doesn't exist, don't call filemtime and don't
display the time.

But why even include the footer in you error page?

Christoph Michael Becker

unread,
Apr 23, 2014, 3:38:48 PM4/23/14
to
Nonsense. I should have read the OP more carefully in the first place.

Of course, it makes no sense to try to show the last modification time
of an error document, and even less of a non existing resource.

--
Christoph M. Becker

Christoph Michael Becker

unread,
Apr 23, 2014, 3:46:15 PM4/23/14
to
Jerry Stuckle wrote:

> On 4/23/2014 8:21 AM, Christoph Michael Becker wrote:
>> Thomas 'PointedEars' Lahn:
>>
>>> Look closely at that warning. This approach is not going to work
>>> reliably
>>> because the HTTP request URI does not need to have anything to do
>>> with the
>>> file path of the resource. In fact, there does not even need to be a
>>> real
>>> file for a URI, the served content could have been generated entirely
>>> by PHP
>>> (and usually is). As a result, in those cases filemtime() returns
>>> FALSE …
>>
>> ACK.
>>
>>> You might be looking for filemtime(__FILE__) instead.
>>
>> __FILE__ contains the filepath of the currently *included* file; in Ed's
>> case the following should be more appropriate:
>>
>
> True - which in this case would be the footer, not the requested page.
>
>> filemtime($_SERVER['SCRIPT_NAME']);
>>
>
> Unfortunately, this, too, may or may not have any relationship to the
> file system.

Indeed, you're right. Thanks for pointing that out.

I was mislead by the ambiguous documentation in the PHP manual[1], which
states:

| Contains the current script's path.

The CGI 1.1 specification[2] clarifies this:

| The SCRIPT_NAME variable MUST be set to a URI path (not URL-encoded)
| which could identify the CGI script

[1] <http://www.php.net/manual/en/reserved.variables.server.php>
[2] <https://tools.ietf.org/html/rfc3875#section-4.1.13>

--
Christoph M. Becker

Jerry Stuckle

unread,
Apr 23, 2014, 4:36:49 PM4/23/14
to
There are two problems here. The first one comes when you use the
Apache rewrite option to rewrite URIs. This is commonly done with CMS's
where the actual pages are in a database, and one file handles all of
the requests (but is often used in other situations, also). In such a
case, there is no separate file.

The second problem comes in when you use the Alias (or ScriptAlias)
Apache directive to dynamically alter file paths (similar to a Linux
symlink, but on a virtual server by virtual server basis). I use the
latter regularly for images which are common to multiple websites, for
instance. So the request my refer to /images/logo.png, but the real
location is /var/www/images/logo.php (doc root would be
/var/www/sitename/html). And cgi scripts may be in /user/bin/cgi, but
the URL points to /cgi-bin.

Of course, if you don't use any of the above, the file system will
reflect the document root with the URL appended.

Denis McMahon

unread,
Apr 23, 2014, 5:28:37 PM4/23/14
to
On Wed, 23 Apr 2014 14:22:29 -0400, Ed Mullen wrote:

> Tried various things and decided to apply the KISS method. Made a
> separate footer text file for the custom error files without the "last
> modified" code in it.

Actually, the KISS method would be a basic 404.html with nothing in it
that might break if something changes in php, the server config, the
phase of the moon etc.

--
Denis McMahon, denismf...@gmail.com

Thomas 'PointedEars' Lahn

unread,
Apr 23, 2014, 6:27:49 PM4/23/14
to
Christoph Michael Becker wrote:

> Jerry Stuckle wrote:
>> On 4/23/2014 8:21 AM, Christoph Michael Becker wrote:
>>> filemtime($_SERVER['SCRIPT_NAME']);
>>>
>>
>> Unfortunately, this, too, may or may not have any relationship to the
>> file system.
>
> Indeed, you're right. Thanks for pointing that out.
>
> I was mislead by the ambiguous documentation in the PHP manual[1], which
> states:
>
> | Contains the current script's path.
>
> The CGI 1.1 specification[2] clarifies this:
>
> | The SCRIPT_NAME variable MUST be set to a URI path (not URL-encoded)
> | which could identify the CGI script

and

| The SCRIPT_NAME string forms some leading part of the path component
| of the Script-URI derived in some implementation-defined manner.
$_SERVER['SCRIPT_NAME'] WFM for forms and links (“action” and “href”
attributes).

$_SERVER['SCRIPT_FILENAME'] WFM for script files.


PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm> (404-comp.)

Ed Mullen

unread,
Apr 23, 2014, 8:19:43 PM4/23/14
to
Indeed, see my other reply in this thread.


--
Ed Mullen
http://edmullen.net/
As I said before, I never repeat myself.

Christoph Michael Becker

unread,
Apr 24, 2014, 6:35:43 PM4/24/14
to
Thomas 'PointedEars' Lahn wrote:

> Christoph Michael Becker wrote:
>
>> Jerry Stuckle wrote:
>>> On 4/23/2014 8:21 AM, Christoph Michael Becker wrote:
>>>> filemtime($_SERVER['SCRIPT_NAME']);
>>>>
>>>
>>> Unfortunately, this, too, may or may not have any relationship to the
>>> file system.
>>
>> Indeed, you're right. Thanks for pointing that out.
>>
>> I was mislead by the ambiguous documentation in the PHP manual[1], which
>> states:
>>
>> | Contains the current script's path.
>>
>> The CGI 1.1 specification[2] clarifies this:
>>
>> | The SCRIPT_NAME variable MUST be set to a URI path (not URL-encoded)
>> | which could identify the CGI script
>
> and
>
> | The SCRIPT_NAME string forms some leading part of the path component
> | of the Script-URI derived in some implementation-defined manner.
>
>> [1] <http://www.php.net/manual/en/reserved.variables.server.php>
>> [2] <https://tools.ietf.org/html/rfc3875#section-4.1.13>
>
> $_SERVER['SCRIPT_NAME'] WFM for forms and links (“action” and “href”
> attributes).
>
> $_SERVER['SCRIPT_FILENAME'] WFM for script files.

Thanks for the pointer. I just found $_SERVER['PATH_TRANSLATED'], which
might be even more appropriate, if available. Apparently, these
variables have to be used on a "WFM" basis, as there doesn't seem to be
any "standardized" specification.

--
Christoph M. Becker
0 new messages