Re: [PHP] questions about $_SERVER
On Sat, Mar 10, 2012 at 7:43 PM, Tedd Sperling wrote: > On Mar 10, 2012, at 3:53 PM, tamouse mailing lists wrote: >> On Sat, Mar 10, 2012 at 9:37 AM, Tedd Sperling >> wrote: >>> That's correct, but to access those variables outside of their scope (such >>> as a function) you do via a SuperGlobal, namely $GLOBAL['whatever']. >>> >>> As such, there are no "globals" in PHP other than SuperGlobals. As I said, >>> if I'm wrong, please show me otherwise. >> >> I guess I don't know what you mean by "globals". I know what globals >> are, but not "globals". > > I don't understand your question. I know what questions are, but not your > question. :-) Well, I've been pondering this for a while, and now I'm sure. -> kill file -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] questions about $_SERVER
Stuart Dallas wrote: [snip] so $GLOBALS['GLOBALS']['GLOBALS']['GLOBALS']['_SERVER'] is a perfectly valid, if daft, way of accessing $_SERVER. -Stuart Now this is becoming educational! ;-) Donovan -- D Brooke -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] questions about $_SERVER
On 13 Mar 2012 at 15:59, Tedd Sperling wrote: > I'm not sure what would have saved bacon in the above case. I don't see how > your example would work. I think it contained a typo. > > In what I think you were trying to demonstrate, I would just pass $x by > reference (&$x) -- or -- return $x by value. I would not have used a global, > > In any event, I seldom use globals anyway. This was more an academic > discussion. As was my example - and yes, it had a typo. Worse, trying it in a shell it doesn't exhibit the failure mode I thought I'd had. Never mind. -- Cheers -- Tim -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] questions about $_SERVER
On Mar 13, 2012, at 12:20 PM, Stuart Dallas wrote: > On 13 Mar 2012, at 15:59, Tedd Sperling wrote: > >> In any event, I seldom use globals anyway. This was more an academic >> discussion. > -snip- > It ultimately also means that only the superglobals are true globals. That was my initial statement in this thread. After 47 years of programming, I think I'm beginning to get the idea. :-) As I've said for many years "I've learned something new every day of my life -- and I'm getting damned tried of it." Cheers, tedd _ tedd.sperl...@gmail.com http://sperling.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] questions about $_SERVER
On 13 Mar 2012, at 15:59, Tedd Sperling wrote: > In any event, I seldom use globals anyway. This was more an academic > discussion. If you're being academic about it please remember that the way PHP defines globals is different to most other languages. PHP: A variable defined at the top-level scope. World: A variable that is visible at every scope. This is an important difference if you ever move from PHP to another language. It ultimately also means that only the superglobals are true globals. The $GLOBALS superglobal contains all variables defined at the top-level scope, including $GLOBALS, so $GLOBALS['GLOBALS']['GLOBALS']['GLOBALS']['_SERVER'] is a perfectly valid, if daft, way of accessing $_SERVER. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] questions about $_SERVER
On Tue, Mar 13, 2012 at 4:59 PM, Tedd Sperling wrote: > On Mar 12, 2012, at 7:12 PM, Tim Streater wrote: >> > >> function yes ($a) >> { >> global $x; >> if ($a) $x = "yes\n"; >> } >> >> first (true); >> >> echo $x; >> >> ?> >> >> >> but I haven't looked into $GLOBALS enough to know whether using them instead >> would have saved my bacon. > > I'm not sure what would have saved bacon in the above case. I don't see how > your example would work. I think it contained a typo. > > In what I think you were trying to demonstrate, I would just pass $x by > reference (&$x) -- or -- return $x by value. I would not have used a global, > > In any event, I seldom use globals anyway. This was more an academic > discussion. > > Cheers, > > tedd > I would indeed mark it as bad practice using them. I only use them for debugging purposes. When developing something, you might end up needing some global variable temporary, and you don't want to pass it through a few dozen functions before reaching the one where you need it. - Matijn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] questions about $_SERVER
On Mar 12, 2012, at 12:04 PM, Daniel Brown wrote: > On Sun, Mar 11, 2012 at 14:16, Tedd Sperling wrote: >> This document clearly states that $GLOBALS is a SuperGlobal -- what am I not >> understanding here? > >You are understanding it correctly, the only thing that's missing > is the population. The variables are defined (set), but not all are > populated. $GLOBALS is a superglobal, you're right; globals set from > userland scripts are not superglobals, but do wind up in the $GLOBALS > array. Thus, all superglobals are globals, but not all globals are > superglobals. So, it's a question of population timing -- I see. Additionally, I like the term "userland" -- I will use it in class. :-) What would be the opposite term, serverland? Thanks, tedd _ tedd.sperl...@gmail.com http://sperling.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] questions about $_SERVER
On Mar 12, 2012, at 7:12 PM, Tim Streater wrote: > > function yes ($a) > { > global $x; > if ($a) $x = "yes\n"; > } > > first (true); > > echo $x; > > ?> > > > but I haven't looked into $GLOBALS enough to know whether using them instead > would have saved my bacon. I'm not sure what would have saved bacon in the above case. I don't see how your example would work. I think it contained a typo. In what I think you were trying to demonstrate, I would just pass $x by reference (&$x) -- or -- return $x by value. I would not have used a global, In any event, I seldom use globals anyway. This was more an academic discussion. Cheers, tedd _ tedd.sperl...@gmail.com http://sperling.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] questions about $_SERVER
On 12 Mar 2012 at 20:07, Tedd Sperling wrote: > Tim: > > I read somewhere that using: > > global $x; > > is not recommended. Whereas, it is recommended to use: > > $x = $GLOBALS['x']; > echo $x; Tedd, That may well be, although as I write I can't recollect having seen that anywhere; so I don't use that form. However I have been caught by something like the following: but I haven't looked into $GLOBALS enough to know whether using them instead would have saved my bacon. -- Cheers -- Tim -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] questions about $_SERVER
The purpose of the "global" statement within a function is to let PHP know that the usage of a var name INSIDE that function is not meant to create a NEW variable, but instead, to reference the other (global) variable being used (and perhaps already defined) in your main script. Basically it works like this: You can: - create vars in the main script usable in that script's main body outside of any functions - create vars to be used entirely and only within any functions in your script; -reference vars from the main script within a specific function by referencing them with a "global $xxx,$yyy,$zzz" statement at the top of your function; And Finally You Can: - create $_SESSION['xxx'] var that can be seen anywhere in your application(s) during the life of the current session. Close the browser or fail to do a "session_start()" in a script and you can't see them, but who would do that? I'm sure someone will have something else to add, but I think this is all the knowledge one needs to accomplish most php programming. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] questions about $_SERVER
On Mar 11, 2012, at 3:04 PM, Tim Streater wrote: > > In the following, $x is a global but not a super-global (AFAIK). > > > > function echox () > { > > global $x; > > echo $x; > > } > > $x = "Hello world\n"; > > echox (); > > ?> > > -- > Cheers -- Tim Tim: I read somewhere that using: global $x; is not recommended. Whereas, it is recommended to use: $x = $GLOBALS['x']; echo $x; In any event, what I found interesting is: print_r($GLOBALS) if will list all the variables (plus more) in your script. Thus, all variables in your main script are also included in the $GLOBALS array. Cheers, tedd _ tedd.sperl...@gmail.com http://sperling.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] questions about $_SERVER
On Sun, Mar 11, 2012 at 14:16, Tedd Sperling wrote: > > As to placing an additional requirement (i.e., being predefined) on the > definition as to what constitutes a SuperGlobal is outside my understanding. > As such, I must defer to the PHP Manual, namely: > > http://php.net/manual/en/language.variables.superglobals.php > > This document clearly states that $GLOBALS is a SuperGlobal -- what am I not > understanding here? You are understanding it correctly, the only thing that's missing is the population. The variables are defined (set), but not all are populated. $GLOBALS is a superglobal, you're right; globals set from userland scripts are not superglobals, but do wind up in the $GLOBALS array. Thus, all superglobals are globals, but not all globals are superglobals. -- Network Infrastructure Manager http://www.php.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] questions about $_SERVER
On 11 Mar 2012 at 18:16, Tedd Sperling wrote: > On Mar 11, 2012, at 10:25 AM, Daniel Brown wrote: > >> On Sat, Mar 10, 2012 at 10:37, Tedd Sperling wrote: >>> As such, there are no "globals" in PHP other than SuperGlobals. As I said, >>> if I'm wrong, please show me otherwise. >> >>A superglobal is predefined at run-time by the parser, >> environment, SAPI, etc. (_SERVER, _POST, _GET, _REQUEST, _ENV, >> _SESSION, _COOKIE), whereas a global can be defined at any time, and >> is available to the current instance. All superglobals are globals, >> but not all globals are superglobals. > Now I'm confused. > > My understanding is that all variables defined within the main script are > accessible within the main script because they are all within scope by > definition. > > Additionally, main script variables are not accessible out of scope (such as > in a function) unless one uses $GLOBALS to retrieve those values. In the following, $x is a global but not a super-global (AFAIK). -- Cheers -- Tim -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] questions about $_SERVER
On Mar 11, 2012, at 10:25 AM, Daniel Brown wrote: > On Sat, Mar 10, 2012 at 10:37, Tedd Sperling wrote: >> As such, there are no "globals" in PHP other than SuperGlobals. As I said, >> if I'm wrong, please show me otherwise. > >A superglobal is predefined at run-time by the parser, > environment, SAPI, etc. (_SERVER, _POST, _GET, _REQUEST, _ENV, > _SESSION, _COOKIE), whereas a global can be defined at any time, and > is available to the current instance. All superglobals are globals, > but not all globals are superglobals. > > -- > > Network Infrastructure Manager > http://www.php.net/ Now I'm confused. My understanding is that all variables defined within the main script are accessible within the main script because they are all within scope by definition. Additionally, main script variables are not accessible out of scope (such as in a function) unless one uses $GLOBALS to retrieve those values. That is the limit of my understanding of $GLOBALS. As to placing an additional requirement (i.e., being predefined) on the definition as to what constitutes a SuperGlobal is outside my understanding. As such, I must defer to the PHP Manual, namely: http://php.net/manual/en/language.variables.superglobals.php This document clearly states that $GLOBALS is a SuperGlobal -- what am I not understanding here? Cheers, tedd _ tedd.sperl...@gmail.com http://sperling.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] questions about $_SERVER
On Sat, Mar 10, 2012 at 10:37, Tedd Sperling wrote: > As such, there are no "globals" in PHP other than SuperGlobals. As I said, if > I'm wrong, please show me otherwise. A superglobal is predefined at run-time by the parser, environment, SAPI, etc. (_SERVER, _POST, _GET, _REQUEST, _ENV, _SESSION, _COOKIE), whereas a global can be defined at any time, and is available to the current instance. All superglobals are globals, but not all globals are superglobals. -- Network Infrastructure Manager http://www.php.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] questions about $_SERVER
On 11 Mar 2012, at 01:43, Tedd Sperling wrote: > On Mar 10, 2012, at 3:53 PM, tamouse mailing lists wrote: >> On Sat, Mar 10, 2012 at 9:37 AM, Tedd Sperling >> wrote: >>> That's correct, but to access those variables outside of their scope (such >>> as a function) you do via a SuperGlobal, namely $GLOBAL['whatever']. >>> >>> As such, there are no "globals" in PHP other than SuperGlobals. As I said, >>> if I'm wrong, please show me otherwise. >> >> I guess I don't know what you mean by "globals". I know what globals >> are, but not "globals". > > I don't understand your question. I know what questions are, but not your > question. :-) I think the confusion is arising because the word superglobal is used in PHP when referring to globals, because the word global has been incorrectly applied for quite some time. A global variable is a variable that is accessible in every scope, so Tedd is right… the only true globals in PHP are the superglobals. Here's an overview of the various scopes in PHP (I've probably missed some, but it's enough to make the point)… http://php.net/variables.scope $var1 = 'a'; function funcB() { // Only visible inside this function. $var2 = 'b'; } function funcB() { // This statement makes the variable from the top-level scope visible // within this function. Essentially this is the same as passing the // variable in to the function by reference. global $var1; } class classC { // Visible to methods in this class only. private $var3 = 'c'; // Visible to methods in this class and methods in derived classes. protected $var4 = 'd'; // Method visible in this class only. private methodA() { // Visible only inside this method. $var5 = 'e'; } // Method visible in this class and methods in derived classes. protected methodB() { // See funcB() global $var1; } // Method visible on any instance of this class. public methodC() { // See funcB() global $var1; } } ?> The global keyword allows you to expose a variable that has been defined at the top-level scope ($var1 in the above example) in the current scope. It does NOT create a global variable; the keyword is not an accurate reflection of what it does. My guess is that calling the top-level scope "global" made sense when functions were the only other level of scope that existed. Now that we have yet more levels of scope it can be a bit confusing. I hope this helps clear things up. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] questions about $_SERVER
On Mar 10, 2012, at 3:53 PM, tamouse mailing lists wrote: > On Sat, Mar 10, 2012 at 9:37 AM, Tedd Sperling > wrote: >> That's correct, but to access those variables outside of their scope (such >> as a function) you do via a SuperGlobal, namely $GLOBAL['whatever']. >> >> As such, there are no "globals" in PHP other than SuperGlobals. As I said, >> if I'm wrong, please show me otherwise. > > I guess I don't know what you mean by "globals". I know what globals > are, but not "globals". I don't understand your question. I know what questions are, but not your question. :-) Cheers, tedd _ tedd.sperl...@gmail.com http://sperling.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] questions about $_SERVER
On Sat, Mar 10, 2012 at 9:37 AM, Tedd Sperling wrote: > On Mar 9, 2012, at 10:20 PM, Jim Giner wrote: >> "tamouse mailing lists" wrote in message >> news:CAHUC_t8g43GE3xqvSU5SwFePGS1XG=tk1mhrbem9gjaarve...@mail.gmail.com... >>> On Mon, Feb 13, 2012 at 2:39 PM, Tedd Sperling >>> wrote: On Feb 13, 2012, at 4:10 AM, Stuart Dallas wrote: > On 13 Feb 2012, at 06:28, Rui Hu wrote: >> How PHP sets variables in $_SERVER, say, $DOCUMENT_ROOT? What should I >> know >> if I want to modify $_SERVER myself? > > Once your script starts the superglobals are no different to any other > variables, except that they're in scope at all times. That's probably the reason why they are named "SuperGlobals". :-) But to be more descriptive, these are simply globals that are predefined by php -- see: http://php.net/manual/en/language.variables.superglobals.php I believe, (please show me otherwise) there are no "globals" in PHP other than SuperGlobals. >>> >>> Assuming you mean pre-defined ones, there shouldn't be, since no other >>> ones are documented. If there are, then either they should be >>> documented, or they should be ignored as it can be dangerous to use >>> undocumented features. :) >> >> Just to be clear - you asked if it were true that "there are no "globals" in >> PHP other than SuperGlobals: Don't forget that anything that you declare as >> global in a script is a global for that instance of that script (and >> whatever includes, etc. that it calls during its run) > > That's correct, but to access those variables outside of their scope (such as > a function) you do via a SuperGlobal, namely $GLOBAL['whatever']. > > As such, there are no "globals" in PHP other than SuperGlobals. As I said, if > I'm wrong, please show me otherwise. I guess I don't know what you mean by "globals". I know what globals are, but not "globals". -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] questions about $_SERVER
"Tedd Sperling" wrote in message news:315faa8f-3103-4661-b167-d30248952...@gmail.com... On Mar 9, 2012, at 10:20 PM, Jim Giner wrote: > "tamouse mailing lists" wrote in message > news:CAHUC_t8g43GE3xqvSU5SwFePGS1XG=tk1mhrbem9gjaarve...@mail.gmail.com... >> On Mon, Feb 13, 2012 at 2:39 PM, Tedd Sperling >> wrote: >>> On Feb 13, 2012, at 4:10 AM, Stuart Dallas wrote: On 13 Feb 2012, at 06:28, Rui Hu wrote: > How PHP sets variables in $_SERVER, say, $DOCUMENT_ROOT? What should I > know > if I want to modify $_SERVER myself? Once your script starts the superglobals are no different to any other variables, except that they're in scope at all times. >>> >>> That's probably the reason why they are named "SuperGlobals". :-) >>> >>> But to be more descriptive, these are simply globals that are predefined >>> by php -- see: >>> >>> http://php.net/manual/en/language.variables.superglobals.php >>> >>> I believe, (please show me otherwise) there are no "globals" in PHP >>> other >>> than SuperGlobals. >> >> Assuming you mean pre-defined ones, there shouldn't be, since no other >> ones are documented. If there are, then either they should be >> documented, or they should be ignored as it can be dangerous to use >> undocumented features. :) > > Just to be clear - you asked if it were true that "there are no "globals" > in > PHP other than SuperGlobals: Don't forget that anything that you declare > as > global in a script is a global for that instance of that script (and > whatever includes, etc. that it calls during its run) That's correct, but to access those variables outside of their scope (such as a function) you do via a SuperGlobal, namely $GLOBAL['whatever']. As such, there are no "globals" in PHP other than SuperGlobals. As I said, if I'm wrong, please show me otherwise. Cheers, tedd ** Actually - I've never used "$GLOBAL" - I've just referenced them by their name as specified in the "global" statement - so it's not always obvious that a specific var IS a global.I can see thought that you are aware of them so my point is unnecessary. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] questions about $_SERVER
On Mar 9, 2012, at 10:20 PM, Jim Giner wrote: > "tamouse mailing lists" wrote in message > news:CAHUC_t8g43GE3xqvSU5SwFePGS1XG=tk1mhrbem9gjaarve...@mail.gmail.com... >> On Mon, Feb 13, 2012 at 2:39 PM, Tedd Sperling >> wrote: >>> On Feb 13, 2012, at 4:10 AM, Stuart Dallas wrote: On 13 Feb 2012, at 06:28, Rui Hu wrote: > How PHP sets variables in $_SERVER, say, $DOCUMENT_ROOT? What should I > know > if I want to modify $_SERVER myself? Once your script starts the superglobals are no different to any other variables, except that they're in scope at all times. >>> >>> That's probably the reason why they are named "SuperGlobals". :-) >>> >>> But to be more descriptive, these are simply globals that are predefined >>> by php -- see: >>> >>> http://php.net/manual/en/language.variables.superglobals.php >>> >>> I believe, (please show me otherwise) there are no "globals" in PHP other >>> than SuperGlobals. >> >> Assuming you mean pre-defined ones, there shouldn't be, since no other >> ones are documented. If there are, then either they should be >> documented, or they should be ignored as it can be dangerous to use >> undocumented features. :) > > Just to be clear - you asked if it were true that "there are no "globals" in > PHP other than SuperGlobals: Don't forget that anything that you declare as > global in a script is a global for that instance of that script (and > whatever includes, etc. that it calls during its run) That's correct, but to access those variables outside of their scope (such as a function) you do via a SuperGlobal, namely $GLOBAL['whatever']. As such, there are no "globals" in PHP other than SuperGlobals. As I said, if I'm wrong, please show me otherwise. Cheers, tedd _ tedd.sperl...@gmail.com http://sperling.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] questions about $_SERVER
"tamouse mailing lists" wrote in message news:CAHUC_t8g43GE3xqvSU5SwFePGS1XG=tk1mhrbem9gjaarve...@mail.gmail.com... > On Mon, Feb 13, 2012 at 2:39 PM, Tedd Sperling > wrote: >> On Feb 13, 2012, at 4:10 AM, Stuart Dallas wrote: >>> On 13 Feb 2012, at 06:28, Rui Hu wrote: How PHP sets variables in $_SERVER, say, $DOCUMENT_ROOT? What should I know if I want to modify $_SERVER myself? >>> >>> Once your script starts the superglobals are no different to any other >>> variables, except that they're in scope at all times. >> >> That's probably the reason why they are named "SuperGlobals". :-) >> >> But to be more descriptive, these are simply globals that are predefined >> by php -- see: >> >> http://php.net/manual/en/language.variables.superglobals.php >> >> I believe, (please show me otherwise) there are no "globals" in PHP other >> than SuperGlobals. > > Assuming you mean pre-defined ones, there shouldn't be, since no other > ones are documented. If there are, then either they should be > documented, or they should be ignored as it can be dangerous to use > undocumented features. :) Just to be clear - you asked if it were true that "there are no "globals" in PHP other than SuperGlobals: Don't forget that anything that you declare as global in a script is a global for that instance of that script (and whatever includes, etc. that it calls during its run) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] questions about $_SERVER
On Mon, Feb 13, 2012 at 2:39 PM, Tedd Sperling wrote: > On Feb 13, 2012, at 4:10 AM, Stuart Dallas wrote: >> On 13 Feb 2012, at 06:28, Rui Hu wrote: >>> How PHP sets variables in $_SERVER, say, $DOCUMENT_ROOT? What should I know >>> if I want to modify $_SERVER myself? >> >> Once your script starts the superglobals are no different to any other >> variables, except that they're in scope at all times. > > That's probably the reason why they are named "SuperGlobals". :-) > > But to be more descriptive, these are simply globals that are predefined by > php -- see: > > http://php.net/manual/en/language.variables.superglobals.php > > I believe, (please show me otherwise) there are no "globals" in PHP other > than SuperGlobals. Assuming you mean pre-defined ones, there shouldn't be, since no other ones are documented. If there are, then either they should be documented, or they should be ignored as it can be dangerous to use undocumented features. :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] questions about $_SERVER
On Feb 13, 2012, at 4:10 AM, Stuart Dallas wrote: > On 13 Feb 2012, at 06:28, Rui Hu wrote: > >> How PHP sets variables in $_SERVER, say, $DOCUMENT_ROOT? What should I know >> if I want to modify $_SERVER myself? > > Once your script starts the superglobals are no different to any other > variables, except that they're in scope at all times. That's probably the reason why they are named "SuperGlobals". :-) But to be more descriptive, these are simply globals that are predefined by php -- see: http://php.net/manual/en/language.variables.superglobals.php I believe, (please show me otherwise) there are no "globals" in PHP other than SuperGlobals. Cheers, tedd _ t...@sperling.com http://sperling.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] questions about $_SERVER
On 13 Feb 2012, at 06:28, Rui Hu wrote: > How PHP sets variables in $_SERVER, say, $DOCUMENT_ROOT? What should I know > if I want to modify $_SERVER myself? Once your script starts the superglobals are no different to any other variables, except that they're in scope at all times. The only thing you need to bear in mind if you're going to modify them is that other code that's using them will also see your changes, so beware of knock-on effects. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/
Re: [PHP] questions about $_SERVER
On Mon, Feb 13, 2012 at 5:28 PM, Rui Hu wrote: > hi, > > How PHP sets variables in $_SERVER, say, $DOCUMENT_ROOT? What should I know > if I want to modify $_SERVER myself? > > Thanks! > > > -- > Best regards, > > Rui Hu > > State Key Laboratory of Networking & Switching Technology > Beijing University of Posts and Telecommunications(BUPT) > MSN: tchrb...@gmail.com > - Rui, $_SERVER is an associative array. You can access "DOCUMENT_ROOT" with $_SERVER['DOCUMENT_ROOT']. It contains the document root directory under which the current script is executing. You can make changes to the $_SERVER array but it will have no effect on PHP itself. I mean, you can change the value of $_SERVER['DOCUMENT_ROOT'] to whatever you want at runtime, but of course it will not actually change the current directory if that's what you're after. Thanks, Michael -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Questions about $_SERVER
Peter and Paul: Sorry, I went on vacation for a few days (it was a surprise vacation with a 2 day notice). I think you both understand what I was looking for and found what I wanted was not possible. It's just one of those things in life you have to live with. Thanks very much for your time and comment. Cheers, tedd -- --- http://sperling.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Questions about $_SERVER
On Mon, Aug 30, 2010 at 05:13:59PM -0400, Paul M Foster wrote: > On Mon, Aug 30, 2010 at 10:34:42PM +0200, Peter Lind wrote: > > > On 30 August 2010 22:34, Paul M Foster wrote: > > > On Mon, Aug 30, 2010 at 09:53:46PM +0200, Peter Lind wrote: > > > > > > > > >> > $_SERVER['REMOTE_NAME'] > > >> > > > >> > So the question is, how would he get that last variable. It becomes > > >> > complicated when using a shared hosting environment, because server > > >> > names and IPs aren't a 1:1 mapping. An IP may represent numerous > actual > > >> > site names. This was part or all of the reason why the http > protocol was > > >> > revised from 1.0 to 1.1-- in order to accommodate all the domains, > which > > >> > because of the cramped IP space of IPv4, had to share IPs. So in the > > >> > HTTP 1.1 protocol, there is additional information passed about > the name > > >> > of the domain. > > >> > > > >> > > >> In the scenario painted, it's explicitly stated that one server acts > > >> as a client in trying to access a resource on another server. Could > > >> you enlighten me as to where the domain name of a client is located in > > >> the request header fields? Here's the RFC for HTTP 1.1 > > >> http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html#sec5.3 > > > > > > From http://www8.org/w8-papers/5c-protocols/key/key.html: > > > > > > > > > My mistake, though: this change was by no means the only reason for the > > > creation of HTTP 1.1 > > > > Not only that, it has nothing whatsoever to do with the case at hand. > > The Host header field specifies the domain you're asking a resource > > from, not the the domain of the client. Hence, it cannot be used in > > any fashion to provide identification of the client doing the request, > > which is what Tedd wanted. > > Tedd was looking for the server name for the remote server, as seen from > the perspective of the asking server. In his example, he was looking for > a variable which would tell him "Slave's" name from "Master's" > perspective. That's why he was asking if there was anything like > $_SERVER['REMOTE_NAME'] as a known PHP server variable. I'm mistaken here. He's looking for the name of the server making the request, which doesn't appear to be transmitted anywhere. Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Questions about $_SERVER
On Mon, Aug 30, 2010 at 10:34:42PM +0200, Peter Lind wrote: > On 30 August 2010 22:34, Paul M Foster wrote: > > On Mon, Aug 30, 2010 at 09:53:46PM +0200, Peter Lind wrote: > > > >> > $_SERVER['REMOTE_NAME'] > >> > > >> > So the question is, how would he get that last variable. It becomes > >> > complicated when using a shared hosting environment, because server > >> > names and IPs aren't a 1:1 mapping. An IP may represent numerous actual > >> > site names. This was part or all of the reason why the http protocol was > >> > revised from 1.0 to 1.1-- in order to accommodate all the domains, which > >> > because of the cramped IP space of IPv4, had to share IPs. So in the > >> > HTTP 1.1 protocol, there is additional information passed about the name > >> > of the domain. > >> > > >> > >> In the scenario painted, it's explicitly stated that one server acts > >> as a client in trying to access a resource on another server. Could > >> you enlighten me as to where the domain name of a client is located in > >> the request header fields? Here's the RFC for HTTP 1.1 > >> http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html#sec5.3 > > > > From http://www8.org/w8-papers/5c-protocols/key/key.html: > > > > My mistake, though: this change was by no means the only reason for the > > creation of HTTP 1.1 > > Not only that, it has nothing whatsoever to do with the case at hand. > The Host header field specifies the domain you're asking a resource > from, not the the domain of the client. Hence, it cannot be used in > any fashion to provide identification of the client doing the request, > which is what Tedd wanted. Tedd was looking for the server name for the remote server, as seen from the perspective of the asking server. In his example, he was looking for a variable which would tell him "Slave's" name from "Master's" perspective. That's why he was asking if there was anything like $_SERVER['REMOTE_NAME'] as a known PHP server variable. Of course, you're correct in that the HTTP 1.1 spec I cited wouldn't help him. I just mentioned it as being of tangential interest. Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Questions about $_SERVER
On 30 August 2010 22:34, Paul M Foster wrote: > On Mon, Aug 30, 2010 at 09:53:46PM +0200, Peter Lind wrote: > >> On 30 August 2010 21:32, Paul M Foster wrote: >> > On Sun, Aug 29, 2010 at 06:04:23PM +0200, Per Jessen wrote: >> > >> >> Jason Pruim wrote: >> >> >> >> > My understanding of how shared hosting works would make this near >> >> > impossible... Basically Apache grabs a header that is sent at the >> >> > initial connection which includes the destination hostname and from >> >> > there it translates it to the proper directory on the shared host. >> >> > >> >> > All the IP's though are based off of the parent site's server... >> >> > >> >> > Now with dedicated hosting where you have the entire machine you can >> >> > do what you are looking at because the IP address will always >> >> > translate back to your website. >> >> >> >> AFAICT, Tedd was not asking about the server, he's asking about the >> >> client. >> > >> > No, he's talking about the server. But the server he's using may offload >> > the processing of a script to another machine. So >> > >> > $_SERVER['SERVER_ADDR'] and $_SERVER['SERVER_NAME'] >> > >> > both relate to the server which the client is originally communicating >> > with. But he wants to know if he can get the same information about a >> > different remote server which is processing a script for him. The >> > problem is that we have: >> > >> > $_SERVER['REMOTE_ADDR'] >> > >> > but no >> > >> > $_SERVER['REMOTE_NAME'] >> > >> > So the question is, how would he get that last variable. It becomes >> > complicated when using a shared hosting environment, because server >> > names and IPs aren't a 1:1 mapping. An IP may represent numerous actual >> > site names. This was part or all of the reason why the http protocol was >> > revised from 1.0 to 1.1-- in order to accommodate all the domains, which >> > because of the cramped IP space of IPv4, had to share IPs. So in the >> > HTTP 1.1 protocol, there is additional information passed about the name >> > of the domain. >> > >> >> In the scenario painted, it's explicitly stated that one server acts >> as a client in trying to access a resource on another server. Could >> you enlighten me as to where the domain name of a client is located in >> the request header fields? Here's the RFC for HTTP 1.1 >> http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html#sec5.3 > > From http://www8.org/w8-papers/5c-protocols/key/key.html: > > === EXCERPT === > > Internet address conservation > > Companies and organizations use URLs to advertise themselves and their > products and services. When a URL appears in a medium other than the Web > itself, people seem to prefer ``pure hostname'' URLs; i.e., URLs without > any path syntax following the hostname. These are often known as > ``vanity URLs,'' but in spite of the implied disparagement, it's > unlikely that non-purist users will abandon this practice, which has led > to the continuing creation of huge numbers of hostnames. > > IP addresses are widely perceived as a scarce resource (pending the > uncertain transition to IPv6 [DH95]). The Domain Name System (DNS) > allows multiple host names to be bound to the same IP address. > Unfortunately, because the original designers of HTTP did not anticipate > the ``success disaster'' they were enabling, HTTP/1.0 requests do not > pass the hostname part of the request URL. For example, if a user makes > a request for the resource at URL http://example1.org/home.html, the > browser sends a message with the Request-Line > > GET /home.html HTTP/1.0 > > to the server at example1.org. This prevents the binding of another HTTP > server hostname, such as exampleB.org to the same IP address, because > the server receiving such a message cannot tell which server the message > is meant for. Thus, the proliferation of vanity URLs causes a > proliferation of IP address allocations. > > The Internet Engineering Steering Group (IESG), which manages the IETF > process, insisted that HTTP/1.1 take steps to improve conservation of IP > addresses. Since HTTP/1.1 had to interoperate with HTTP/1.0, it could > not change the format of the Request-Line to include the server > hostname. Instead, HTTP/1.1 requires requests to include a Host header, > first proposed by John Franks [Fra94], that carries the hostname. This > converts the example above to: > > GET /home.html HTTP/1.1 > Host: example1.org > > If the URL references a port other than the default (TCP port 80), this > is also given in the Host header. > > Clearly, since HTTP/1.0 clients will not send Host headers, HTTP/1.1 > servers cannot simply reject all messages without them. However, the > HTTP/1.1 specification requires that an HTTP/1.1 server must reject any > HTTP/1.1 message that does not contain a Host header. > > The intent of the Host header mechanism, and in particular the > requirement that enforces its presence in HTTP/1.1 requests, is to speed > the transition away from assigning a new IP a
Re: [PHP] Questions about $_SERVER
On Mon, Aug 30, 2010 at 09:53:46PM +0200, Peter Lind wrote: > On 30 August 2010 21:32, Paul M Foster wrote: > > On Sun, Aug 29, 2010 at 06:04:23PM +0200, Per Jessen wrote: > > > >> Jason Pruim wrote: > >> > >> > My understanding of how shared hosting works would make this near > >> > impossible... Basically Apache grabs a header that is sent at the > >> > initial connection which includes the destination hostname and from > >> > there it translates it to the proper directory on the shared host. > >> > > >> > All the IP's though are based off of the parent site's server... > >> > > >> > Now with dedicated hosting where you have the entire machine you can > >> > do what you are looking at because the IP address will always > >> > translate back to your website. > >> > >> AFAICT, Tedd was not asking about the server, he's asking about the > >> client. > > > > No, he's talking about the server. But the server he's using may offload > > the processing of a script to another machine. So > > > > $_SERVER['SERVER_ADDR'] and $_SERVER['SERVER_NAME'] > > > > both relate to the server which the client is originally communicating > > with. But he wants to know if he can get the same information about a > > different remote server which is processing a script for him. The > > problem is that we have: > > > > $_SERVER['REMOTE_ADDR'] > > > > but no > > > > $_SERVER['REMOTE_NAME'] > > > > So the question is, how would he get that last variable. It becomes > > complicated when using a shared hosting environment, because server > > names and IPs aren't a 1:1 mapping. An IP may represent numerous actual > > site names. This was part or all of the reason why the http protocol was > > revised from 1.0 to 1.1-- in order to accommodate all the domains, which > > because of the cramped IP space of IPv4, had to share IPs. So in the > > HTTP 1.1 protocol, there is additional information passed about the name > > of the domain. > > > > In the scenario painted, it's explicitly stated that one server acts > as a client in trying to access a resource on another server. Could > you enlighten me as to where the domain name of a client is located in > the request header fields? Here's the RFC for HTTP 1.1 > http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html#sec5.3 >From http://www8.org/w8-papers/5c-protocols/key/key.html: === EXCERPT === Internet address conservation Companies and organizations use URLs to advertise themselves and their products and services. When a URL appears in a medium other than the Web itself, people seem to prefer ``pure hostname'' URLs; i.e., URLs without any path syntax following the hostname. These are often known as ``vanity URLs,'' but in spite of the implied disparagement, it's unlikely that non-purist users will abandon this practice, which has led to the continuing creation of huge numbers of hostnames. IP addresses are widely perceived as a scarce resource (pending the uncertain transition to IPv6 [DH95]). The Domain Name System (DNS) allows multiple host names to be bound to the same IP address. Unfortunately, because the original designers of HTTP did not anticipate the ``success disaster'' they were enabling, HTTP/1.0 requests do not pass the hostname part of the request URL. For example, if a user makes a request for the resource at URL http://example1.org/home.html, the browser sends a message with the Request-Line GET /home.html HTTP/1.0 to the server at example1.org. This prevents the binding of another HTTP server hostname, such as exampleB.org to the same IP address, because the server receiving such a message cannot tell which server the message is meant for. Thus, the proliferation of vanity URLs causes a proliferation of IP address allocations. The Internet Engineering Steering Group (IESG), which manages the IETF process, insisted that HTTP/1.1 take steps to improve conservation of IP addresses. Since HTTP/1.1 had to interoperate with HTTP/1.0, it could not change the format of the Request-Line to include the server hostname. Instead, HTTP/1.1 requires requests to include a Host header, first proposed by John Franks [Fra94], that carries the hostname. This converts the example above to: GET /home.html HTTP/1.1 Host: example1.org If the URL references a port other than the default (TCP port 80), this is also given in the Host header. Clearly, since HTTP/1.0 clients will not send Host headers, HTTP/1.1 servers cannot simply reject all messages without them. However, the HTTP/1.1 specification requires that an HTTP/1.1 server must reject any HTTP/1.1 message that does not contain a Host header. The intent of the Host header mechanism, and in particular the requirement that enforces its presence in HTTP/1.1 requests, is to speed the transition away from assigning a new IP address for every vanity URL. However, as long as a substantial fraction of the users on the Internet use browsers that do not send Host, no Web site operator (such as an electronic commerce b
Re: [PHP] Questions about $_SERVER
On 30 August 2010 21:32, Paul M Foster wrote: > On Sun, Aug 29, 2010 at 06:04:23PM +0200, Per Jessen wrote: > >> Jason Pruim wrote: >> >> > My understanding of how shared hosting works would make this near >> > impossible... Basically Apache grabs a header that is sent at the >> > initial connection which includes the destination hostname and from >> > there it translates it to the proper directory on the shared host. >> > >> > All the IP's though are based off of the parent site's server... >> > >> > Now with dedicated hosting where you have the entire machine you can >> > do what you are looking at because the IP address will always >> > translate back to your website. >> >> AFAICT, Tedd was not asking about the server, he's asking about the >> client. > > No, he's talking about the server. But the server he's using may offload > the processing of a script to another machine. So > > $_SERVER['SERVER_ADDR'] and $_SERVER['SERVER_NAME'] > > both relate to the server which the client is originally communicating > with. But he wants to know if he can get the same information about a > different remote server which is processing a script for him. The > problem is that we have: > > $_SERVER['REMOTE_ADDR'] > > but no > > $_SERVER['REMOTE_NAME'] > > So the question is, how would he get that last variable. It becomes > complicated when using a shared hosting environment, because server > names and IPs aren't a 1:1 mapping. An IP may represent numerous actual > site names. This was part or all of the reason why the http protocol was > revised from 1.0 to 1.1-- in order to accommodate all the domains, which > because of the cramped IP space of IPv4, had to share IPs. So in the > HTTP 1.1 protocol, there is additional information passed about the name > of the domain. > In the scenario painted, it's explicitly stated that one server acts as a client in trying to access a resource on another server. Could you enlighten me as to where the domain name of a client is located in the request header fields? Here's the RFC for HTTP 1.1 http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html#sec5.3 Regards Peter -- WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind BeWelcome/Couchsurfing: Fake51 Twitter: http://twitter.com/kafe15 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Questions about $_SERVER
On Sun, Aug 29, 2010 at 06:04:23PM +0200, Per Jessen wrote: > Jason Pruim wrote: > > > My understanding of how shared hosting works would make this near > > impossible... Basically Apache grabs a header that is sent at the > > initial connection which includes the destination hostname and from > > there it translates it to the proper directory on the shared host. > > > > All the IP's though are based off of the parent site's server... > > > > Now with dedicated hosting where you have the entire machine you can > > do what you are looking at because the IP address will always > > translate back to your website. > > AFAICT, Tedd was not asking about the server, he's asking about the > client. No, he's talking about the server. But the server he's using may offload the processing of a script to another machine. So $_SERVER['SERVER_ADDR'] and $_SERVER['SERVER_NAME'] both relate to the server which the client is originally communicating with. But he wants to know if he can get the same information about a different remote server which is processing a script for him. The problem is that we have: $_SERVER['REMOTE_ADDR'] but no $_SERVER['REMOTE_NAME'] So the question is, how would he get that last variable. It becomes complicated when using a shared hosting environment, because server names and IPs aren't a 1:1 mapping. An IP may represent numerous actual site names. This was part or all of the reason why the http protocol was revised from 1.0 to 1.1-- in order to accommodate all the domains, which because of the cramped IP space of IPv4, had to share IPs. So in the HTTP 1.1 protocol, there is additional information passed about the name of the domain. Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Questions about $_SERVER
On 29 August 2010 18:04, Per Jessen wrote: > Jason Pruim wrote: > >> My understanding of how shared hosting works would make this near >> impossible... Basically Apache grabs a header that is sent at the >> initial connection which includes the destination hostname and from >> there it translates it to the proper directory on the shared host. >> >> All the IP's though are based off of the parent site's server... >> >> Now with dedicated hosting where you have the entire machine you can >> do what you are looking at because the IP address will always >> translate back to your website. > The HTTP protocol does not provide a domain among the request header fields - you need to implement idenfication/authentication in a different manner (preferably in a way that does not rely upon IP addresses, seeing as that doesn't provide any reliable sort of identification). Regards Peter -- WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind BeWelcome/Couchsurfing: Fake51 Twitter: http://twitter.com/kafe15 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Questions about $_SERVER
Jason Pruim wrote: > My understanding of how shared hosting works would make this near > impossible... Basically Apache grabs a header that is sent at the > initial connection which includes the destination hostname and from > there it translates it to the proper directory on the shared host. > > All the IP's though are based off of the parent site's server... > > Now with dedicated hosting where you have the entire machine you can > do what you are looking at because the IP address will always > translate back to your website. AFAICT, Tedd was not asking about the server, he's asking about the client. -- Per Jessen, Zürich (17.2°C) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Questions about $_SERVER
At 11:54 AM -0400 8/29/10, Jason Pruim wrote: On Aug 29, 2010, at 10:55 AM, tedd wrote: To all: My post about SERVER globals was simply an observation that the SERVER global report of host and remote was not symmetric -- for example you could obtain both the IP and Domain Name of the host, but only the IP of the remote. Sorry for any confusion I may have caused in my post. Hey tedd, My understanding of how shared hosting works would make this near impossible... Basically Apache grabs a header that is sent at the initial connection which includes the destination hostname and from there it translates it to the proper directory on the shared host. All the IP's though are based off of the parent site's server... Now with dedicated hosting where you have the entire machine you can do what you are looking at because the IP address will always translate back to your website. Now hopefully my understanding of shared hosting isn't flawed but if it is I'm sure someone will nicely point out why :) Your understanding is the same as my understanding. Cheers, tedd -- --- http://sperling.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Questions about $_SERVER
On Aug 29, 2010, at 10:55 AM, tedd wrote: At 10:56 AM +0200 8/29/10, Peter Lind wrote: On 29 August 2010 08:08, Jim Lucas wrote: *snip* Their is not existing variable (if you would) that your server, when connecting to a remote server, would be sending. So, to have the remote end be able to identify the initiating host identity, the initiating side would have to add some something to the headers or pass it along in the body of the request itself. +1. Let the requestion script send through identification/ authentification. Regards Peter To all: My post about SERVER globals was simply an observation that the SERVER global report of host and remote was not symmetric -- for example you could obtain both the IP and Domain Name of the host, but only the IP of the remote. Sorry for any confusion I may have caused in my post. As to the reason why I was asking, please review my next post, namely "Secure Communication?" Cheers, tedd Hey tedd, My understanding of how shared hosting works would make this near impossible... Basically Apache grabs a header that is sent at the initial connection which includes the destination hostname and from there it translates it to the proper directory on the shared host. All the IP's though are based off of the parent site's server... Now with dedicated hosting where you have the entire machine you can do what you are looking at because the IP address will always translate back to your website. Now hopefully my understanding of shared hosting isn't flawed but if it is I'm sure someone will nicely point out why :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Questions about $_SERVER
At 10:56 AM +0200 8/29/10, Peter Lind wrote: On 29 August 2010 08:08, Jim Lucas wrote: *snip* Their is not existing variable (if you would) that your server, when connecting to a remote server, would be sending. So, to have the remote end be able to identify the initiating host identity, the initiating side would have to add some something to the headers or pass it along in the body of the request itself. +1. Let the requestion script send through identification/authentification. Regards Peter To all: My post about SERVER globals was simply an observation that the SERVER global report of host and remote was not symmetric -- for example you could obtain both the IP and Domain Name of the host, but only the IP of the remote. Sorry for any confusion I may have caused in my post. As to the reason why I was asking, please review my next post, namely "Secure Communication?" Cheers, tedd -- --- http://sperling.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Questions about $_SERVER
On 29 August 2010 08:08, Jim Lucas wrote: *snip* > Their is not existing variable (if you would) that your server, when > connecting to a remote server, would be sending. So, to have the remote end > be able to identify the initiating host identity, the initiating side would > have to add some something to the headers or pass it along in the body of > the request itself. > +1. Let the requestion script send through identification/authentification. Regards Peter -- WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind BeWelcome/Couchsurfing: Fake51 Twitter: http://twitter.com/kafe15 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Questions about $_SERVER
tedd wrote: At 12:15 AM +0200 8/29/10, Peter Lind wrote: On 28 August 2010 23:45, tedd wrote: > So, I'm trying to figure out a compliment to $_SERVER['SERVER_NAME'] such as something like $_SERVER['REMOTE_NAME']. > Is there such a beast? You're not making any sense. For the script on your local host to be able to connect and communicate with the remote host, it would need to know the name of the remote host. Hence, the local host already knows the name and has no reason to ask the remote host for a name by which to contact it. That's what I get from your description of the problem. You probably want to clarify some things. Regards Peter Peter: Sorry for not making sense. But sometimes you have to confirm the players (both server and remote) in communications. Try this -- place this script on your site: You will note that: [SERVER_NAME] => is the domain name of your site. Also: [SERVER_ADDR] => is the IP of your site. If you are on a shared host, then it will still be the IP of the main host. Please note: [REMOTE_ADDR] => is the IP of the remote server. It *will be* the IP of the remote main host regardless of if the requesting script is running on the remote main host OR is running under a remote shared host. Here's an example: My site http://webbytedd.com is running on a shared host. The server address reported for this site is: 74.208.162.186 However, if I enter 74.208.162.186 into a browser, I do not arrive at webbytedd.com, but instead go to securelayer.com who is my host. Now, if webbytedd.com was the requesting script, how could the original script know what domain name the request came from? As it is now, it can only know the main host ID, but not the domain name of the requesting script. Does that make my question any clearer? So my questions basically is -- how can I discover the actual domain name of the remote script when it is running on a shared server? Their is not existing variable (if you would) that your server, when connecting to a remote server, would be sending. So, to have the remote end be able to identify the initiating host identity, the initiating side would have to add some something to the headers or pass it along in the body of the request itself. What type of service are you trying to create on your server? And what protocol would it be using to connect to the remote server? If you are using cURL, you could add something to the headers before you send the request. But, if you are using something like fopen or file_get_contents, you are stuck. You would not be able to modify the headers being sent in the request. If you are in need of identifying the initial server from the second server, then I would suggest using cURL and adding something unique to the headers before you send the request to the remote server. Hope that is clear as mud. I hope that makes better sense. Cheers, tedd -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Questions about $_SERVER
Sorry, forgot to include the mailing list email when I replied to this originally... On Aug 28, 2010, at 8:28 PM, tedd wrote: Sorry for not making sense. But sometimes you have to confirm the players (both server and remote) in communications. Try this -- place this script on your site: You will note that: [SERVER_NAME] => is the domain name of your site. Also: [SERVER_ADDR] => is the IP of your site. If you are on a shared host, then it will still be the IP of the main host. Please note: [REMOTE_ADDR] => is the IP of the remote server. It *will be* the IP of the remote main host regardless of if the requesting script is running on the remote main host OR is running under a remote shared host. Here's an example: My site http://webbytedd.com is running on a shared host. The server address reported for this site is: 74.208.162.186 However, if I enter 74.208.162.186 into a browser, I do not arrive at webbytedd.com, but instead go to securelayer.com who is my host. Now, if webbytedd.com was the requesting script, how could the original script know what domain name the request came from? As it is now, it can only know the main host ID, but not the domain name of the requesting script. Does that make my question any clearer? So my questions basically is -- how can I discover the actual domain name of the remote script when it is running on a shared server? I hope that makes better sense. Cheers, tedd I really don't understand what you mean by "remote script" -- most requests are made by clients. REMOTE_ADDR is the IP address of the *client* - i.e. the requesting system. It may or may not be a script. And it may or may not have an accessible hostname. Is this a situation where you are establishing a service that is to be called by other servers, i.e, some form of API? If not, and if it is a case of a browser client calling a PHP script on your server, most browser clients aren't running on very useful hostnames for the outside world anyway. E.g. the hostname of my mac is "paladin.local" but it obviously can't be called by the outside world by that name. Maybe tell us what you are trying to accomplish by knowing the hostname of the calling machine? Maybe there's another way. Are you trying to set up two-way communication between the two servers? Normally, communication is established without regard for the calling machine's hostname, because it's going through the connection established by the web server. PHP just returns info along that connection to the calling machine. It seems you would only need to know the requesting system's hostname if you were going to establish some other channel of communication with it, i.e., if your original script was somehow going to call back the calling machine, webbytedd.com to do some other kind of activity. If that *is* what you're doing, I can probably guarantee there's a better way to do it. However, if what you're after is *authenticating* that the requester is who they say they are, there are ways to do that as well without knowing the requesting host's name (and better than knowing the requesting host's name, you can establish authenticity and access control for a particular script which is much better than just establishing blanket authority for a particular hostname). However, I'm really reaching here with trying to understand what you want to accomplish by knowing the requesting machine's hostname. So, please, explain what you are trying to do and maybe we can help with that. Tamara -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Questions about $_SERVER
At 12:15 AM +0200 8/29/10, Peter Lind wrote: On 28 August 2010 23:45, tedd wrote: > So, I'm trying to figure out a compliment to $_SERVER['SERVER_NAME'] such as something like $_SERVER['REMOTE_NAME']. > Is there such a beast? You're not making any sense. For the script on your local host to be able to connect and communicate with the remote host, it would need to know the name of the remote host. Hence, the local host already knows the name and has no reason to ask the remote host for a name by which to contact it. That's what I get from your description of the problem. You probably want to clarify some things. Regards Peter Peter: Sorry for not making sense. But sometimes you have to confirm the players (both server and remote) in communications. Try this -- place this script on your site: You will note that: [SERVER_NAME] => is the domain name of your site. Also: [SERVER_ADDR] => is the IP of your site. If you are on a shared host, then it will still be the IP of the main host. Please note: [REMOTE_ADDR] => is the IP of the remote server. It *will be* the IP of the remote main host regardless of if the requesting script is running on the remote main host OR is running under a remote shared host. Here's an example: My site http://webbytedd.com is running on a shared host. The server address reported for this site is: 74.208.162.186 However, if I enter 74.208.162.186 into a browser, I do not arrive at webbytedd.com, but instead go to securelayer.com who is my host. Now, if webbytedd.com was the requesting script, how could the original script know what domain name the request came from? As it is now, it can only know the main host ID, but not the domain name of the requesting script. Does that make my question any clearer? So my questions basically is -- how can I discover the actual domain name of the remote script when it is running on a shared server? I hope that makes better sense. Cheers, tedd -- --- http://sperling.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Questions about $_SERVER
On 28 August 2010 23:45, tedd wrote: > At 9:41 PM +0200 8/28/10, Per Jessen wrote: >> >> tedd wrote: >> > >>> >>> So, how can I identify the exact location of the 'server_addr' and of >>> the 'remote_addr' on shared hosting? Is that possible? >> >> $_SERVER['SERVER_NAME'] will tell you the name of the virtual host - I >> don't know if that is what you're after. >> >> -- >> Per Jessen, Zürich (12.2°C) > > Certainly, $_SERVER['SERVER_NAME'] will tell you the name of the virtual > host, but what about the virtual remote? > > You see, I can have a script on one server communicate with another script > on a another server and the remote addresses reported on either will not > translate back to their respective virtual hosts, but instead to their > hosts. > > So, I'm trying to figure out a compliment to $_SERVER['SERVER_NAME'] such as > something like $_SERVER['REMOTE_NAME']. > > Is there such a beast? > You're not making any sense. For the script on your local host to be able to connect and communicate with the remote host, it would need to know the name of the remote host. Hence, the local host already knows the name and has no reason to ask the remote host for a name by which to contact it. That's what I get from your description of the problem. You probably want to clarify some things. Regards Peter -- WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind BeWelcome/Couchsurfing: Fake51 Twitter: http://twitter.com/kafe15 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Questions about $_SERVER
At 9:41 PM +0200 8/28/10, Per Jessen wrote: tedd wrote: > So, how can I identify the exact location of the 'server_addr' and of the 'remote_addr' on shared hosting? Is that possible? $_SERVER['SERVER_NAME'] will tell you the name of the virtual host - I don't know if that is what you're after. -- Per Jessen, Zürich (12.2°C) Certainly, $_SERVER['SERVER_NAME'] will tell you the name of the virtual host, but what about the virtual remote? You see, I can have a script on one server communicate with another script on a another server and the remote addresses reported on either will not translate back to their respective virtual hosts, but instead to their hosts. So, I'm trying to figure out a compliment to $_SERVER['SERVER_NAME'] such as something like $_SERVER['REMOTE_NAME']. Is there such a beast? Cheers, tedd -- --- http://sperling.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Questions about $_SERVER
tedd wrote: > Hi gang: > > The server global: > > $_SERVER['SERVER_ADDR'] > > Provides the IP of the server where the current script is executing. > > And, the server global: > > $_SERVER['REMOTE_ADDR'] > > Provides the IP of the server executing the script. Yes, aka the client address. > As such, you can enter the IP of either into a browser and see that > specific domain. Huh? If my server is 192.168.29.104 and my client is 192.168.29.114, I might get the default website on the server address, and nothing on the client (assuming it is not running a webserver). > However, that doesn't work when you are dealing with shared hosting. > Doing that will show you to the parent domain, but not the child > domain (i.e., alias). > > So, how can I identify the exact location of the 'server_addr' and of > the 'remote_addr' on shared hosting? Is that possible? $_SERVER['SERVER_NAME'] will tell you the name of the virtual host - I don't know if that is what you're after. -- Per Jessen, Zürich (12.2°C) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Questions about $_SERVER
Hi gang: The server global: $_SERVER['SERVER_ADDR'] Provides the IP of the server where the current script is executing. And, the server global: $_SERVER['REMOTE_ADDR'] Provides the IP of the server executing the script. As such, you can enter the IP of either into a browser and see that specific domain. However, that doesn't work when you are dealing with shared hosting. Doing that will show you to the parent domain, but not the child domain (i.e., alias). So, how can I identify the exact location of the 'server_addr' and of the 'remote_addr' on shared hosting? Is that possible? Thanks, Cheers, tedd -- --- http://sperling.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php