Re: Re: header
| From: | Micah Gersten | Date: | Wed, 17 Sep 2008 06:40:04 +0000 |
| Subject: | Re: Re: header | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-280338@lists.php.net to get a copy of this message | ||
Wouldn't it be nice if in the $_SERVER array you could get the whole URL
now that PHP has a parse_url function?
Thank you,
Micah Gersten
onShore Networks
Internal Developer
http://www.onshore.com
Jochem Maas wrote:
> Robert Cummings schreef:
>> On Tue, 2008-09-16 at 21:18 +0100, Nathan Rixham wrote:
>>> Jim Lucas wrote:
>>>> Robert Cummings wrote:
>>>>> On Tue, 2008-09-16 at 18:13 +0100, Nathan Rixham wrote:
>>>>>> I also meant:
>>>>>> define('PUBLIC_BASE_HREF' ,
>>>>>> 'http://php.net/')
>>>>>> <head>
>>>>>> <base href="<?php echo PUBLIC_BASE_HREF; ?>" />
>>>>>> </head>
>>>>>>
>>>>>> and further thinking there has to be an easier / cleaner way of
>>>>>> getting "http://" /
>>>>>> "https://" in php..
>>>>> What's wrong with $_SERVER['HTTPS'] ?
>>>>>
>>>>> Cheers,
>>>>> Rob.
>>>> my way
>>>>
>>>> <?php
>>>>
>>>> function get_http_protocol() {
>>>> $proto = 'http';
>>>> if ( isset($_SERVER['HTTPS']) &&
>>>> strtolower($_SERVER['HTTPS'])
>>>> !== 'off' ) {
>>>> $proto .= 's';
>>>> }
>>>> return $proto . '://'; # Adding the :// is optionial
>>>> }
>>>>
>>>> echo get_http_protocol();
>>>>
>>>> ?>
>>>>
>>>> That is about as simple as you can get.
>>>>
>>> lol this one's got my brain going; here's mine:
>>>
>>> <?php
>>> function get_http_protocol() {
>>> return 'http' . ($_SERVER['SERVER_PORT'] == 443 ? 's'
>>> : '') .
>>> '://';
>>> }
>>> echo get_http_protocol();
>>> ?>
>>
>> Just because 443 is the default HTTPS port, doesn't mean HTTPS is being
>> served over 443, nor does it mean HTTPS isn't also being served over
>> another port. This is less effective than using $_SERVER['HTTPS'].
>
> although I hazard to offer the following as more complete:
>
> function get_http_protocol()
> {
> $proto = 'http';
> if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] &&
> strtolower($_SERVER['HTTPS']) !== 'off') {
> $proto .= 's';
> }
>
> return $proto . '://'; # Adding the :// is optionial
> }
>
> because if $_SERVER['HTTPS'] happens to be false (which I don't think
> it ever should be) it
> would cause the return value to be 'https://' which I
> don't think
> would be correct in that case
> (even thought the case is theoretical and likely to indicate an engine
> problem if it did occur)
>
>>
>> Cheers,
>> Rob.
>
>