tags:

views:

65

answers:

3

I'm not familiar with Suhosin (never used it) but if possible I need to check using PHP whether it is installed. This is for part of an installer that I'm writing. Thanks.

+2  A: 
extension_loaded('suhosin');

PHP docs for extension_loaded.

If the extension doesn't load, it may still be available through dl:

if (!extension_loaded('suhosin')) {
    if (!dl('suhosin.so')) {
        // Extension not loaded.
        return false;
    }
}

// Extension loaded.
return true;
strager
This will not work if you compiled suhosin as a part of your PHP interpreter. Installing as the extension in not the only way of installation. http://www.hardened-php.net/suhosin/how_to_install_or_upgrade.html
netme
@netme, I wasn't aware of this, sorry.
strager
+2  A: 

I found only that there is the way to determine it - to put phpinfo() output to variable and to check Suhosin keywords:

<?php
ob_start();
phpinfo();
$phpinfo = ob_get_contents();
ob_end_clean();
if (strpos($phpinfo, "Suhosin") !== FALSE)
    echo "Installed";
?>
netme
A: 

You can test if a configuration open is set for Suhosin:

$isSuhosinInstalled = ini_get('suhosin.session.max_id_length') !== '';
strager
This will not work on all systems with Suhosin installed too. On many systems Suhosin is unconfigured by default. I tried on my 2 hostings, on both variables were not initialized.
netme
@netme, Odd; I thought PHP filled in the default value if it was missing from the actual configuration files. Oh well.
strager