phpinfo Test File

driveflexfuel

New Member
Messages
159
Reaction score
0
Points
0
Before you say it I know all about <?php phpinfo();?>

I am checking to see if anyone has developed a decent check file. Something where if php is installed it says Php is installed and then displays the info. If it is not installed it displays something like sorry php is not installed.

I am packaging a program I developed and would like a file people can download and check if the software will work on their server.

I also need to check whether zend is installed on the server. If someone has such a file I would not have a problem with you placing an advertisement such as Powered by and your website. I would also place your business on my partners page as a backlink.
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
You can easily roll your own using ini_get_all and get_loaded_extensions. Since you want users to be able to check whether their server meets the requirements for your package, you can run the checks in a script, rather than forcing users to pour over lists of extensions, configuration options and other info.

pkginfo.php:
PHP:
<?php
$package = array(
  'name' => 'Foonly Sprockets',
  'minPHPVer' => '5.0.2',
  /* an array in 'required' is a list of alternates; any one of
     them will satisfy the extension requirement. Basically,
     requirements are in conjunctive normal form.
   */
  'required' => array('Zend Optimizer', 
                      array('PDO', 'mysqli'))
);?>
reqschecks.php:
PHP:
<?php
include('pkgInfo.php');
if (version_compare(PHP_VERSION, $package['minPHPVer'], '<')){
    $failures['version'] = "At least PHP $package[minPHPVer] is required (you have " 
                           . PHP_VERSION . ").";
}

$loaded = get_loaded_extensions();
$missing = array_diff($package['required'], $loaded);
foreach ($missing as $i => $ext) {
	if (is_array($ext)) {
		if (array_intersect($ext, $loaded)) {
			unset($missing[$i]);
		} else {
			$missing[$i] = 'one of: ' . implode(', ', $ext) . ';';
		}
	}
}
if ($missing) {
    $failures['extensions'] = "Your host is missing the following PHP extensions required for this package: " 
                              . implode(', ', $missing);
}?>

compatibility.php:
PHP:
<p>Running compatibility checks. If you see no results, your server doesn't have PHP installed and is thus incompatible.</p>
<?php
include('reqschecks.php');
if ($failures) {
  ?><p>Your server isn't compatible with <?php 
      if (False) { ?>this package<?php }
      echo $package['name']; 
    ?>. Reasons:</p>
  <ul>
    <li><?php
       // the following is only visible if this file isn't processed by PHP
       if (False) { ?>PHP isn't installed.<?php }
       echo implode("</li>\n<li>", $failures);
       ?></li>
  </ul><?php
} else {
  // use echo so that no output is produced if PHP isn't installed
    echo "<p>Your server is compatible with $package[name].</p>";
}
 
Last edited:

lemon-tree

x10 Minion
Community Support
Messages
1,420
Reaction score
46
Points
48
I am checking to see if anyone has developed a decent check file. Something where if php is installed it says Php is installed and then displays the info. If it is not installed it displays something like sorry php is not installed.
You might want to be careful checking if PHP is installed with a PHP script. For PHP extensions it will be fine, but if PHP itself isn't installed the users will just see the PHP code itself.
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
if PHP itself isn't installed the users will just see the PHP code itself.
Note that the PHP code won't be visible in the rendered view, only the source view. Though slightly tricky to execute, you can make use of this to give visual feedback on whether or not the file was processed by PHP.
 

marshian

New Member
Messages
526
Reaction score
9
Points
0
Just put the php code in a certain html element, and use Javascript to check client-side what the contents of this element are. If the contents is the code, there is no php. You can then use Javascript to display that.
Quick and dirty not-tested example:
HTML:
<html>
	<head>
		<script type="text/javascript">
			// Or whatever the correct way is, I haven't used JS in a while
			document.onload = checkPhp();
			
			function checkPhp() {
				if (document.getElementById("php").innerHtml == "<" + "?php echo \"Testing\"; ?"+">")
					alert ("There is no php support.");
			}
		</script>
	</head>
	<body>
		<div id="php"><?php echo "Testing"; ?></div>
	</body>
</html>
 
Last edited:
Top