Re: Detecting HTTPS connections under Apache

From: Date: Sat, 28 May 2011 02:38:49 +0000
Subject: Re: Detecting HTTPS connections under Apache
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-313179@lists.php.net to get a copy of this message
$_SERVER['HTTPS'] <?php if($_SERVER['HTTPS']){ echo 'you are secured'; }else{ echo 'you are not secured'; } ?> --Curtis On 5/26/2011 3:37 PM, Geoff Shang wrote:
Hi, Apologies if this is covered somewhere but I've searched fairly extensively and not found anything. I'm working on an application which has a function for redirecting to a given URL. This is generally used for redirecting after a form has been submitted. Right now it sends an HTTP URL in the redirection, which means it can't work under a secure connection. I'd like to be able to use it over HTTPS but don't want to force people to do this. So ideally I'd like to be able to detect the protocol in use and send the appropriate protocol in the Location header. The problem is that, at least on the system I'm working on, I can't see any way of detecting the protocol. _SERVER["SERVER_SIGNATURE"] and _SERVER["SERVER_ADDR"] both give the port as 80, even if I specify port 443 in the URL. I've seen references to _SERVER["HTTPS"] or something similar but it's not in the output I get from either "print_r ($_SERVER)" or "phpinfo ()". I'm running PHP Version 5.3.3-7+squeeze1 on Apache/2.2.16 (Debian). The machine is an x86-64 VPS running Debian Squeeze. I have full access to the VPS, so if something needs tweeking in Apache (or anything else) then I can do this. Thanks in advance, Geoff.


« previous php.general (#313179) next »