NYCPHP Meetup

NYPHP.org

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

Jon Baer jonbaer at jonbaer.com
Sat Jul 15 11:11:18 EDT 2006


Its just not possible then if Apache can start SSL w/o a cert and on  
another port than 443 (although unlikely in a common setup).  I think  
the original question pertained to mod_rewriting some URLs to a  
secure port if its setup w/o a manual configuration switch, the only  
other thing I can think of is either using a low level ext, like  
PHPcap (http://alcane.newffr.com/phpcap/) or something like reading  
banners once w/ another tool ... "nmap -sV -oG - -p 443 localhost |  
egrep open" ...

More overkill but it would be the difference between if it is setup  
vs. it is running I guess :-)

There is also an alternative method on the doc page, did you check  
that out?

http://us3.php.net/apache_get_modules

He reads the httpd.conf file to determine if LoadModules does pull in  
SSL.

- Jon

On Jul 14, 2006, at 10:22 PM, Rolan Yang wrote:

> Apache can be started without the SSL regardless of the certificate's
> existence.
> I just tested my code below and phpinfo reports https even when apache
> isn't listening on 443.
> Sorry. You can toss it all out the window! :(
>
> ~Rolan
>
> Jon Baer wrote:
>> This may sound like a dumb question but wouldn't a test for a
>> specific certificate file somehow be a better sign that SSL is setup?
>>
>> Like attaching a check, if (file_exists('/some/path/cert.pem'))  
>> header
>> ("Location: https://secure/path/");
>>
>> ?
>>
>> - Jon
>>
>> On Jul 14, 2006, at 8:37 PM, Rolan Yang wrote:
>>
>>
>>> 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
>>>>
>>>>
>>> _______________________________________________
>>> New York PHP Community Talk Mailing List
>>> http://lists.nyphp.org/mailman/listinfo/talk
>>> New York PHP Conference and Expo 2006
>>> http://www.nyphpcon.com
>>> Show Your Participation in New York PHP
>>> http://www.nyphp.org/show_participation.php
>>>
>>>
>>>
>>
>> _______________________________________________
>> New York PHP Community Talk Mailing List
>> http://lists.nyphp.org/mailman/listinfo/talk
>> New York PHP Conference and Expo 2006
>> http://www.nyphpcon.com
>> Show Your Participation in New York PHP
>> http://www.nyphp.org/show_participation.php
>>
>>
> _______________________________________________
> New York PHP Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
> New York PHP Conference and Expo 2006
> http://www.nyphpcon.com
> Show Your Participation in New York PHP
> http://www.nyphp.org/show_participation.php
>
>




More information about the talk mailing list