NYCPHP Meetup

NYPHP.org

[nycphp-talk] Use php to check for ssl/https support in apache

Rolan Yang rolan at omnistep.com
Fri Jul 14 20:37:51 EDT 2006


Here are 2 ways to do it without resorting to fopen.. Only applies if 
your https is on the same server. The first is cleaner than the second, 
but neither are guaranteed to work. Use at your own risk.

function check_https() {
        ob_start();
        phpinfo(INFO_GENERAL);
        $phpinfo = ob_get_contents();
        ob_end_clean();
        $s=strpos($phpinfo,'Registered PHP Streams');
        $e=strpos($phpinfo,"\n",$s);
        if (strstr(substr($phpinfo,$s,$e-$s),'https')) {
                return TRUE;
        }
        else {
                return FALSE;
        }
}

function check_https2() {
        ob_start();
        phpinfo(INFO_GENERAL);
        $test=strstr(ob_get_contents(),'https');
        ob_end_clean();
        if ($test) { return TRUE;}
        else {return FALSE;}
}

~Rolan

Rob Marscher wrote:
> Hi All,
>
> I've done a bit of searching and haven't been able to find if there's a 
> means that php running on apache can determine if apache supports 
> ssl/https connections.  It would be nice my app to force an https 
> connection on certain pages if it is available.  Otherwise I'll have to 
> do it with a manual config switch.
>
> Running apache_get_modules() and checking for mod_ssl seems like an 
> option... but doesn't work on PHP 4.4.2 w/ Apache 1.3 which a lot of 
> production servers still use.  Any other ideas?
>
> Thanks a lot,
> Rob
>   



More information about the talk mailing list