+ Reply to Thread
Results 1 to 5 of 5

Thread: phpinfo Test File

  1. #1
    driveflexfuel is offline x10 Sophmore driveflexfuel is an unknown quantity at this point
    Join Date
    Jul 2008
    Posts
    159

    phpinfo Test File

    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.

  2. #2
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: phpinfo Test File

    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 Code:
    <?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 Code:
    <?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 Code:
    <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 by misson; 04-30-2010 at 06:08 PM.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  3. #3
    lemon-tree's Avatar
    lemon-tree is offline x10 Minion lemon-tree has a spectacular aura about
    Join Date
    Nov 2007
    Posts
    1,420

    Re: phpinfo Test File

    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.

  4. #4
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: phpinfo Test File

    Quote Originally Posted by lemon-tree View Post
    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.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  5. #5
    marshian's Avatar
    marshian is offline x10 Elder marshian is an unknown quantity at this point
    Join Date
    Jan 2008
    Location
    Belgium
    Posts
    526

    Re: phpinfo Test File

    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 Code:
    <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 by marshian; 05-01-2010 at 08:59 AM.
    Real programmers don't document their code - if it was hard to write, it should be hard to understand.

+ Reply to Thread

Similar Threads

  1. phpinfo()
    By infoyote in forum Programming Help
    Replies: 1
    Last Post: 04-14-2008, 08:08 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers