FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Today's Messages (on)  | Unread Messages (off) | Subscribed Forums (off) | Subscribed Topics (off) | Unanswered Messages (off)

Forum: comp.lang.php
 Topic: 404 error
Re: 404 error [message #185632 is a reply to message #185621] Wed, 23 April 2014 02:56
Anders Wegge Keller is currently offline  Anders Wegge Keller
Messages: 30
Registered: May 2012
Karma:
Member
add to buddy list
ignore all messages by this user
Jerry Stuckle <jstucklex(at)attglobal(dot)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.*
Re: 404 error [message #185633 is a reply to message #185632] Wed, 23 April 2014 07:12
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 674
Registered: October 2010
Karma:
Senior Member
add to buddy list
ignore all messages by this user
Anders Wegge Keller wrote:

> Jerry Stuckle <jstucklex(at)attglobal(dot)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).
Re: 404 error [message #185634 is a reply to message #185633] Wed, 23 April 2014 07:23
Anders Wegge Keller is currently offline  Anders Wegge Keller
Messages: 30
Registered: May 2012
Karma:
Member
add to buddy list
ignore all messages by this user
Thomas 'PointedEars' Lahn <PointedEars(at)web(dot)de> writes:

> Anders Wegge Keller wrote:
>
>> Jerry Stuckle <jstucklex(at)attglobal(dot)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.

/Wegge

Leder efter redundant peering af dk.*,linux.debian.*
Re: 404 error [message #185635 is a reply to message #185634] Wed, 23 April 2014 07:36
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 674
Registered: October 2010
Karma:
Senior Member
add to buddy list
ignore all messages by this user
Anders Wegge Keller wrote:

> Thomas 'PointedEars' Lahn <PointedEars(at)web(dot)de> writes:
>> Anders Wegge Keller wrote:
>>> Jerry Stuckle <jstucklex(at)attglobal(dot)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.

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.


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 #185636 is a reply to message #185632] Wed, 23 April 2014 08:08
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2491
Registered: September 2010
Karma:
Senior Member
add to buddy list
ignore all messages by this user
On 4/23/2014 2:56 AM, Anders Wegge Keller wrote:
> Jerry Stuckle <jstucklex(at)attglobal(dot)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...


--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex(at)attglobal(dot)net
==================
Re: 404 error [message #185637 is a reply to message #185634] Wed, 23 April 2014 08:09
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2491
Registered: September 2010
Karma:
Senior Member
add to buddy list
ignore all messages by this user
On 4/23/2014 7:23 AM, Anders Wegge Keller wrote:
> Thomas 'PointedEars' Lahn <PointedEars(at)web(dot)de> writes:
>
>> Anders Wegge Keller wrote:
>>
>>> Jerry Stuckle <jstucklex(at)attglobal(dot)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.
>
> /Wegge
>
> Leder efter redundant peering af dk.*,linux.debian.*
>

So? Just trying to make yourself heard?


--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex(at)attglobal(dot)net
==================
Re: 404 error [message #185638 is a reply to message #185626] Wed, 23 April 2014 08:21
Christoph Michael Bec is currently offline  Christoph Michael Bec
Messages: 168
Registered: June 2013
Karma:
Senior Member
add to buddy list
ignore all messages by this user
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
Re: 404 error [message #185639 is a reply to message #185638] Wed, 23 April 2014 09:12
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2491
Registered: September 2010
Karma:
Senior Member
add to buddy list
ignore all messages by this user
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.


--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex(at)attglobal(dot)net
==================
Re: 404 error [message #185640 is a reply to message #185638] Wed, 23 April 2014 09:56
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 674
Registered: October 2010
Karma:
Senior Member
add to buddy list
ignore all messages by this user
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.

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$8300dec7(at)news(dot)demon(dot)co(dot)uk>
Re: 404 error [message #185641 is a reply to message #185640] Wed, 23 April 2014 12:00
Christoph Michael Bec is currently offline  Christoph Michael Bec
Messages: 168
Registered: June 2013
Karma:
Senior Member
add to buddy list
ignore all messages by this user
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(dot)2fb(dot)17(dot)1(at)news(dot)alt(dot)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
Re: 404 error [message #185642 is a reply to message #185613] Wed, 23 April 2014 12:39
Ed Mullen is currently offline  Ed Mullen
Messages: 10
Registered: January 2014
Karma:
Junior Member
add to buddy list
ignore all messages by this user
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?
Re: 404 error [message #185643 is a reply to message #185619] Wed, 23 April 2014 13:12
Ed Mullen is currently offline  Ed Mullen
Messages: 10
Registered: January 2014
Karma:
Junior Member
add to buddy list
ignore all messages by this user
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 #185644 is a reply to message #185642] Wed, 23 April 2014 14:22
Ed Mullen is currently offline  Ed Mullen
Messages: 10
Registered: January 2014
Karma:
Junior Member
add to buddy list
ignore all messages by this user
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)?
Re: 404 error [message #185645 is a reply to message #185643] Wed, 23 April 2014 14:50
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2491
Registered: September 2010
Karma:
Senior Member
add to buddy list
ignore all messages by this user
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
==================
Re: 404 error [message #185646 is a reply to message #185641] Wed, 23 April 2014 15:38
Christoph Michael Bec is currently offline  Christoph Michael Bec
Messages: 168
Registered: June 2013
Karma:
Senior Member
add to buddy list
ignore all messages by this user
Christoph Michael Becker wrote:

> 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(dot)2fb(dot)17(dot)1(at)news(dot)alt(dot)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.

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
SCRIPT_NAME (was: 404 error) [message #185647 is a reply to message #185639] Wed, 23 April 2014 15:46
Christoph Michael Bec is currently offline  Christoph Michael Bec
Messages: 168
Registered: June 2013
Karma:
Senior Member
add to buddy list
ignore all messages by this user
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 16:36
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2491
Registered: September 2010
Karma:
Senior Member
add to buddy list
ignore all messages by this user
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 #185649 is a reply to message #185644] Wed, 23 April 2014 17:28
Denis McMahon is currently offline  Denis McMahon
Messages: 575
Registered: September 2010
Karma:
Senior Member
add to buddy list
ignore all messages by this user
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, denismfmcmahon(at)gmail(dot)com
Re: SCRIPT_NAME [message #185650 is a reply to message #185647] Wed, 23 April 2014 18:27
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 674
Registered: October 2010
Karma:
Senior Member
add to buddy list
ignore all messages by this user
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.


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.)
Re: 404 error [message #185651 is a reply to message #185645] Wed, 23 April 2014 20:19
Ed Mullen is currently offline  Ed Mullen
Messages: 10
Registered: January 2014
Karma:
Junior Member
add to buddy list
ignore all messages by this user
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.



Current Time: Wed Apr 23 23:39:51 EDT 2014

Total time taken to generate the page: 0.02200 seconds