473,883 Members | 2,607 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

__SELF__?

I love the __FILE__ constant; it's been enormously useful. Is there a
constant that would be the equivalent of $PHP_SELF? That's also a useful
value, but according to the docs, "...may or may not [exist] in $_SERVER."
In a distributed app, may or may not doesn't fly. I'm surprised, if there
isn't a reliable way to retrieve this value.

--
Alan Little
Phorm PHP Form Processor
http://www.phorm.com/
May 10 '06
37 6065
Carved in mystic runes upon the very living rock, the last words of Tim
Van Wassenhove of comp.lang.php make plain:
On 2006-05-10, Alan Little <al**@n-o-s-p-a-m-phorm.com> wrote:
I love the __FILE__ constant; it's been enormously useful. Is there a
constant that would be the equivalent of $PHP_SELF? That's also a
useful value, but according to the docs, "...may or may not [exist]
in $_SERVER." In a distributed app, may or may not doesn't fly. I'm
surprised, if there isn't a reliable way to retrieve this value.
Why would you want the value? I still have to see my first good reason
to use it ;)


It allows a script to find out where it's installed (which can also be
done with __FILE__ of course), and for an included file or a function to
know where it's being called from.
(In case you want to redirect a user to the same place
where he came from after a form submit, using '#' as value for the
action is as good and it doesn't has the potential security issues as
$_SERVER['PHP_SELF'] has...)


Another great reason for it to be a constant, like __FILE__.

--
Alan Little
Phorm PHP Form Processor
http://www.phorm.com/
May 11 '06 #11
Carved in mystic runes upon the very living rock, the last words of Alan
Little of comp.lang.php make plain:
Carved in mystic runes upon the very living rock, the last words of
Tim Van Wassenhove of comp.lang.php make plain:
On 2006-05-10, Alan Little <al**@n-o-s-p-a-m-phorm.com> wrote:
I love the __FILE__ constant; it's been enormously useful. Is there
a constant that would be the equivalent of $PHP_SELF?


Why would you want the value? I still have to see my first good
reason to use it ;)


It allows a script to find out where it's installed (which can also be
done with __FILE__ of course),


Actually, I misspoke. $PHP_SELF gives the URL path; __FILE__ gives the
filesystem path. So, the path info of $PHP_SELF can be useful, as well.

--
Alan Little
Phorm PHP Form Processor
http://www.phorm.com/
May 11 '06 #12
Alan Little wrote:
Carved in mystic runes upon the very living rock, the last words of
Jerry Stuckle of comp.lang.php make plain:

Alan Little wrote:
I love the __FILE__ constant; it's been enormously useful. Is there a
constant that would be the equivalent of $PHP_SELF? That's also a
useful value, but according to the docs, "...may or may not [exist]
in $_SERVER." In a distributed app, may or may not doesn't fly. I'm
surprised, if there isn't a reliable way to retrieve this value.


If it's supplied by the web server, it's available. But PHP cannot
guarantee what the servers give PHP.

__FILE__, OTOH, is under complete control of PHP, so PHP can guarantee
its existence.

I understand; that's what I like about __FILE__. I was wondering if there
were a similar constant with the same value as $PHP_SELF.


Not that's guaranteed to be provided by every host. $_SERVER['PHP_SELF'] (the
real name - it's a member of the $_SERVER array) is good because it's always the
name of the page being displayed. That has to be gotten from the server.

But I wouldn't worry about it. It's available in Apache and IIS. Those account
for > 99% of the servers on the web.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
May 11 '06 #13
Alan Little wrote:
Carved in mystic runes upon the very living rock, the last words of NC of
comp.lang.php make plain:

Alan Little wrote:
I love the __FILE__ constant; it's been enormously useful.
Is there a constant that would be the equivalent of $PHP_SELF?
That's also a useful value, but according to the docs, "...may
or may not [exist] in $_SERVER."


This is a sweeping generalization; under Apache and IIS,
$_SERVER['PHP_SELF'] is always available.

I wish it were, but I've encountered instances where it wasn't.


Can you be more specific? I've never seen a case on Apache or IIS where it
isn't available.

Perhaps someone overwrite the $_SERVER array?

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
May 11 '06 #14
On Thu, 11 May 2006 08:43:28 -0400, Jerry Stuckle wrote:
I love the __FILE__ constant; it's been enormously useful. Is there a
constant that would be the equivalent of $PHP_SELF? That's also a
useful value, but according to the docs, "...may or may not [exist] in
$_SERVER. "

This is a sweeping generalization; under Apache and IIS,
$_SERVER['PHP_SELF'] is always available.

I wish it were, but I've encountered instances where it wasn't.

Can you be more specific? I've never seen a case on Apache or IIS where
it isn't available.

Perhaps someone overwrite the $_SERVER array?


Or PHP configured as a CLI binary (AFAIK $_SERVER is only available to
apache modules and ISAPI modules).

Cheers,
Andy

--
Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer
http://www.gphpedit.org | PHP editor for Gnome 2
http://www.andyjeffries.co.uk | Personal site and photos

May 11 '06 #15

Alan Little wrote:
Carved in mystic runes upon the very living rock, the last words of
Chung Leong of comp.lang.php make plain:
Alan Little wrote:
I love the __FILE__ constant; it's been enormously useful. Is there a
constant that would be the equivalent of $PHP_SELF? That's also a
useful value, but according to the docs, "...may or may not [exist]
in $_SERVER." In a distributed app, may or may not doesn't fly. I'm
surprised, if there isn't a reliable way to retrieve this value.


PHP_SELF should always be present in a web environment.


I agree, but it isn't always. I've run into trouble relying on it in Phorm.


Under what situation do you not see PHP_SELF? It's obviously possible
that a certain version of a SAPI module is buggy. The point is it's
supposed to be there.

May 11 '06 #16
Alan Little wrote:
(In case you want to redirect a user to the same place
where he came from after a form submit, using '#' as value for the
action is as good and it doesn't has the potential security issues as
$_SERVER['PHP_SELF'] has...)


Another great reason for it to be a constant, like __FILE__.

--
Alan Little
Phorm PHP Form Processor
http://www.phorm.com/


__FILE__ is actually a language construct--hence its place in the list
of reserved words.

I think Tim is right about PHP_SELF not being terribly useful. I use
it often enouogh myself, but can't really offer any rational reason to
do so. It's some weird, subconscious mistrust of the browser, I think.

May 11 '06 #17
On 2006-05-10, John Dunlop <us*********@jo hn.dunlop.name> wrote:
Tim Van Wassenhove:
Why would you want the value? I still have to see my first good reason
to use it ;) (In case you want to redirect a user to the same place
where he came from after a form submit, using '#' as value for the
action is as good and it doesn't has the potential security issues as
$_SERVER['PHP_SELF'] has...)


I remember a similar discussion a while ago, and I went away thinking
there was something wrong with my PHP. I still don't know what
PHP_SELF is meant to be.


[snip bug reports]

Here is an example of possible abuse of forms that use
$_SERVER['PHP_SELF']: http://blog.phpdoc.info/archives/13-XSS-Woes.html

--
Met vriendelijke groeten,
Tim Van Wassenhove <http://timvw.madoka.be >
May 11 '06 #18
Andy Jeffries wrote:
On Thu, 11 May 2006 08:43:28 -0400, Jerry Stuckle wrote:
>I love the __FILE__ constant; it's been enormously useful. Is there a
>constant that would be the equivalent of $PHP_SELF? That's also a
>useful value, but according to the docs, "...may or may not [exist] in
>$_SERVER ."

This is a sweeping generalization; under Apache and IIS,
$_SERVER['PHP_SELF'] is always available.
I wish it were, but I've encountered instances where it wasn't.


Can you be more specific? I've never seen a case on Apache or IIS where
it isn't available.

Perhaps someone overwrite the $_SERVER array?

Or PHP configured as a CLI binary (AFAIK $_SERVER is only available to
apache modules and ISAPI modules).

Cheers,
Andy


Good point, Andy. I never use PHP as a CLI, and completely forgot that one.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
May 11 '06 #19
Andy Jeffries wrote:

Or PHP configured as a CLI binary (AFAIK $_SERVER is only available to
apache modules and ISAPI modules).


I'm pretty sure that $_SERVER, along with $_GET, $_POST, and $_COOKIE
are available in PHP-CLI. They're built fairly deep inside PHP.
There's no easy way to rip them out. It's certainly not worth the
effort, as you'll only end up breaking things.

Only session and file support support are removed from CLI if I
remember correctly.

May 11 '06 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1939
by: Jacek Generowicz | last post by:
Where can I find information on the __self__ attribute of builtin functions ?
2
3241
by: Hallvard B Furuseth | last post by:
What's the difference between a built-in method and a method-wrapper object? Why has only the former a __self__, even though both are tied to the object on which to perform the operation? Why do list.pop and list.__len__ have different types at all? >>> .pop.__self__ >>> .__len__.__self__ Traceback (most recent call last): File "<stdin>", line 1, in ?
0
9933
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
9786
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10734
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10836
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10407
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5794
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5982
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4607
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4211
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.