Re: differences in between these env. variables

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Jan 11, 2012 at 5:49 PM, Matijn Woudt <tijnema@xxxxxxxxx> wrote:
> On Thu, Jan 12, 2012 at 12:26 AM, Haluk Karamete
> <halukkaramete@xxxxxxxxx> wrote:
>> I've grouped these env variables, each group returns the same values
>> is there a difference? which ones do you use? which ones should I not
>> use for the purposes listed below
>>
> You can find the answers here:
> http://nl3.php.net/manual/en/reserved.variables.server.php
> I'll try to answer them in short
>
>> group1
>> SCRIPT_FILENAME vs PATH_TRANSLATED
>> where both return D:\Hosting\5291100\html\directory\file.php
>> purpose: get the full file path to the php script
>>
> SCRIPT_FILENAME can be a relative path, PATH_TRANSLATED is the full
> path. This is only true if run from CLI.
> On my Ubuntu box I don't even have PATH_TRANSLATED, so SCRIPT_FILENAME
> is recommended.
>>
>> group2
>> REMOTE_ADDR vs REMOTE_HOST
>> where both return same IP
>> purpose: get the visitor's ip
>
> REMOTE_HOST is not necessary always IP, if PHP succeeds to do a
> reverse lookup (ie. get name for this ip), than REMOTE_HOST contains a
> name instead of ip. You need to set a config option for this, though.
> Recommended: REMOTE_ADDR, it matches what you need, doesn't need
> config, and REMOTE_HOST doesn't even work for all hosts.
>>
>> group3
>> REQUEST_URI vs SCRIPT_NAME vs URL vs ORIG_PATH_INFO vs PHP_SELF
>> which all return  /directory/file.php
>> purpose: get the virtual url to the php script
>
> I'll extend your example. We now have a RewriteRule in apache like this:
>
> RewriteRule ^files/?$ /directory/file.php [L,QSA]
>
> Which will rewrite /files/... --> /directory/file.php
>
> REQUEST_URI now contains how it was called by the browser,
> '/files/something.php'
> SCRIPT_NAME returns path to script (/directory/file.php), set by the
> SAPI (apache, ..).
> PHP_SELF returns also the path to script (/directory/file.php), but
> set by PHP self.
> I don't have any ORIG_PATH_INFO on my Ubuntu box, so be careful about this one.
>
> Recommended: Depends on which you need. I prefer PHP_SELF over
> SCRIPT_NAME, but that's more personal choice.
>
> Matijn
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

Is there ever a case where SCRIPT_NAME does not equal PHP_SELF?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux