404 error [message #185613] |
Tue, 22 April 2014 16:41  |
Ed Mullen
Messages: 11 Registered: January 2014
Karma: 0
|
Junior Member |
|
|
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.
|
|
|
|
|
|
|
Re: 404 error [message #185619 is a reply to message #185616] |
Tue, 22 April 2014 18:42   |
Lew Pitcher
Messages: 60 Registered: April 2013
Karma: 0
|
Member |
|
|
On Tuesday 22 April 2014 13:32, in comp.lang.php, "Ed Mullen"
<ejEVOMER(at)edmullen(dot)net> wrote:
> Ed Mullen wrote:
>> Jerry Stuckle wrote:
>>> On 4/22/2014 12:41 PM, 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.
>>>>
>>>> <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.
>>>>
>>>
>>> If the file doesn't exist, how can you get its time?
>>>
>>
>> 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
>>
>
> 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.
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
|
|
|
Re: 404 error [message #185621 is a reply to message #185619] |
Tue, 22 April 2014 18:56   |
Jerry Stuckle
Messages: 2598 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
On 4/22/2014 2:42 PM, Lew Pitcher wrote:
> On Tuesday 22 April 2014 13:32, in comp.lang.php, "Ed Mullen"
> <ejEVOMER(at)edmullen(dot)net> wrote:
>
>> Ed Mullen wrote:
>>> Jerry Stuckle wrote:
>>>> On 4/22/2014 12:41 PM, 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.
>>>> >
>>>> > <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.
>>>> >
>>>>
>>>> If the file doesn't exist, how can you get its time?
>>>>
>>>
>>> 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
>>>
>>
>> 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.
>
>
> 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
>
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.
--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex(at)attglobal(dot)net
==================
|
|
|
Re: 404 error [message #185626 is a reply to message #185613] |
Tue, 22 April 2014 21:26   |
Thomas 'PointedEars'
Messages: 701 Registered: October 2010
Karma: 0
|
Senior Member |
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: 404 error [message #185643 is a reply to message #185619] |
Wed, 23 April 2014 17:12   |
Ed Mullen
Messages: 11 Registered: January 2014
Karma: 0
|
Junior Member |
|
|
Lew Pitcher wrote:
> On Tuesday 22 April 2014 13:32, in comp.lang.php, "Ed Mullen"
> <ejEVOMER(at)edmullen(dot)net> wrote:
>
>> Ed Mullen wrote:
>>> Jerry Stuckle wrote:
>>>> On 4/22/2014 12:41 PM, 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.
>>>> >
>>>> > <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.
>>>> >
>>>>
>>>> If the file doesn't exist, how can you get its time?
>>>>
>>>
>>> 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
>>>
>>
>> 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.
>
>
> 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
>
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.
|
|
|
|
Re: 404 error [message #185645 is a reply to message #185643] |
Wed, 23 April 2014 18:50   |
Jerry Stuckle
Messages: 2598 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
On 4/23/2014 1:12 PM, Ed Mullen wrote:
> Lew Pitcher wrote:
>> On Tuesday 22 April 2014 13:32, in comp.lang.php, "Ed Mullen"
>> <ejEVOMER(at)edmullen(dot)net> wrote:
>>
>>> Ed Mullen wrote:
>>>> Jerry Stuckle wrote:
>>>> > On 4/22/2014 12:41 PM, 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.
>>>> >>
>>>> >> <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.
>>>> >>
>>>> >
>>>> > If the file doesn't exist, how can you get its time?
>>>> >
>>>>
>>>> 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
>>>>
>>>
>>> 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.
>>
>>
>> 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
>>
>
> 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); ?>
>
>
>
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?
--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex(at)attglobal(dot)net
==================
|
|
|
|
SCRIPT_NAME (was: 404 error) [message #185647 is a reply to message #185639] |
Wed, 23 April 2014 19:46   |
Christoph Michael Bec
Messages: 207 Registered: June 2013
Karma: 0
|
Senior Member |
|
|
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
|
|
|
Re: SCRIPT_NAME [message #185648 is a reply to message #185647] |
Wed, 23 April 2014 20:36   |
Jerry Stuckle
Messages: 2598 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
On 4/23/2014 3:46 PM, Christoph Michael Becker wrote:
> 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>
>
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.
--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex(at)attglobal(dot)net
==================
|
|
|
|
|
Re: 404 error [message #185651 is a reply to message #185645] |
Thu, 24 April 2014 00:19   |
Ed Mullen
Messages: 11 Registered: January 2014
Karma: 0
|
Junior Member |
|
|
Jerry Stuckle wrote:
> On 4/23/2014 1:12 PM, Ed Mullen wrote:
>> Lew Pitcher wrote:
>>> On Tuesday 22 April 2014 13:32, in comp.lang.php, "Ed Mullen"
>>> <ejEVOMER(at)edmullen(dot)net> wrote:
>>>
>>>> Ed Mullen wrote:
>>>> > Jerry Stuckle wrote:
>>>> >> On 4/22/2014 12:41 PM, 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.
>>>> >>>
>>>> >>> <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.
>>>> >>>
>>>> >>
>>>> >> If the file doesn't exist, how can you get its time?
>>>> >>
>>>> >
>>>> > 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
>>>> >
>>>>
>>>> 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.
>>>
>>>
>>> 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
>>>
>>
>> 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); ?>
>>
>>
>>
>
> 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?
>
Indeed, see my other reply in this thread.
--
Ed Mullen
http://edmullen.net/
As I said before, I never repeat myself.
|
|
|
Re: SCRIPT_NAME [message #185653 is a reply to message #185650] |
Thu, 24 April 2014 22:35  |
Christoph Michael Bec
Messages: 207 Registered: June 2013
Karma: 0
|
Senior Member |
|
|
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
|
|
|