Forum Moderators: coopster

Message Too Old, No Replies

missing "s" in secure server url

         

php4U

1:30 am on Apr 1, 2009 (gmt 0)

10+ Year Member



I found an old post on the board from several years ago, and I pieced the strings together to turn a variable into the full url

$page_url = 'http' . ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 's' : '') . '://' .$_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . ($_SERVER['QUERY_STRING']? '?'. $_SERVER['QUERY_STRING'] : '');

This works fine but I do have one question. My server is https capable but when I view it in the browser it doesn't seem to detect the secure connection and the code only shows http in the output.

Can anyone see anything that I might be missing? Thank you for any help.

php4U

11:36 pm on Apr 1, 2009 (gmt 0)

10+ Year Member



coopster provided https code here

[webmasterworld.com ]

maybe I implemented it wrong, but everything works except picking up the s in https://

whoisgregg

12:03 am on Apr 2, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I would recommend doing a print_r($_SERVER) to see if $_SERVER['HTTPS'] is set. On some servers I've had to check the $_SERVER['REMOTE_PORT'] to see if it is 443 because $_SERVER['HTTPS'] wasn't helpful.

coopster

12:15 pm on Apr 2, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Also, if you are visiting an address that is not running over your secured port (http, not https, in your browser address bar):
http://www.example.com/myscript.php

... then the configuration directive will not be present.

php4U

8:20 pm on Apr 2, 2009 (gmt 0)

10+ Year Member



Thank you both for the replies. Chances are I won't need anything with https in it, but since the server has the capabilities I didn't want to exclude it.

print $_SERVER['REMOTE_PORT']

yeilded the following ports in the browser
2485 = normal http://example.com/test.php
2487 = secure layer [example.com...]

print_r($_SERVER);
[example.com...]

yeilded a lot of info and I saw...
[HTTPS] => 1

The other day when I tested this in the secured port
[example.com...] the script picked up the additional www (certificate is registered with www) but only displayed http://www.example.com/test.php

found solution
changed
&& $_SERVER['HTTPS'] == 'on'
to
&& $_SERVER['HTTPS'] == '1'

since 1 was my parameter
[HTTPS] => 1

[edited by: php4U at 8:25 pm (utc) on April 2, 2009]

whoisgregg

8:46 pm on Apr 2, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Glad you got it sorted. :)

php4U

12:40 am on Apr 3, 2009 (gmt 0)

10+ Year Member



Thank you whoisgregg
print_r($_SERVER); helped greatly. A lot of info there that could help with other things in the future.