Pretest Script for testing MySql and PHP Versions and Status of components before install

Posted By: Ian on Dec 17, 2011 in Blog, PHP, Snippets
Last modified on November 6th, 2013 at 8:36 pm,

During the remake of the installation script for bannerbar i had to come up with a pre-test script and with a bit of searching i put together the below which may be helpful for you too.

<?php

//------------------------------------- PHP Version Checker -------------------------------------//

$php_version=phpversion();
if($php_version<5)
{
$error="true";
$php_error="PHP version is $php_version - too old!";
}

//------------------------------------- MySQL Version Checker -------------------------------------//

function find_SQL_Version() { 
$output = shell_exec('mysql -V'); 
preg_match('@[0-9]+\.[0-9]+\.[0-9]+@', $output, $version); 
return @$version[0]?$version[0]:-1; 
}

$mysql_version=find_SQL_Version(); 

if($mysql_version<5)
{
$error="true";
$mysql_error="MySQL version is $mysql_version.";
} 

//------------------------------------- PHP Mail Checker -------------------------------------//

if(!function_exists('mail'))
{
$error="true";
$mail_error="PHP Mail function is not enabled!";
}

//------------------------------------- safe mode Checker -------------------------------------//

//check the status of safe mode
if(ini_get('safe_mode') ){
$error="true";
$safe_mode = "On";
}else{
$safe_mode = "Off";
}

//------------------------------------- PHP Sessions Checker -------------------------------------//

$_SESSION['myscriptname_sessions_work']=1;
if(empty($_SESSION['myscriptname_sessions_work']))
{
$error="true";
$session_error="Sessions must be enabled!";
}

//------------------------------------- register globals Checker -------------------------------------//

if(ini_get('register_globals') ){
$error="true";
$register_globals = "On";
}else{
$register_globals = "Off";
}
?>

<!DOCTYPE html>
<html lang="en-GB">
<head>
<meta charset="UTF-8" />

<style type="text/css">
#container {
background:#f3f3f3;
border:1px solid #000;
font-family:verdana;
font-size:90%;
margin-left:auto;
margin-right:auto;
margin-top:20px;
width:50%
}

#sub-container {
background:#fff;
margin:10px;
padding:15px 20px 10px
}

#header {
border-bottom:1px solid #7db0e3;
}

div#header h1 {
color:#c80000;
font-size:16px;
text-align:center
}

#table {
display:table;
margin-left:auto;
margin-right:auto;
margin-top:10px;
width:550px
}

.row {
display:table-row
}

.cell {
display:table-cell
}

.green {
color:green
}

.red {
color:red
}

#pretest {
text-align:center;
margin-left:auto;
margin-right:auto;
margin-top:10px;
width:350px
}
</style>

<title>Pretest for your program Setup</title>
</head>
<body>
<div id="container">
<div id="sub-container">
<div id="header">
<h1>Pretest for your program Setup</h1>
</div>
<div id="table">
<div class="row">
<span class="cell">PHP Version (Must be 5 or better)</span>
<span class="cell">
<?php if(empty($php_error)) echo "<span class='green'>$php_version - OK!</span>";
else echo "<span class='red'>$php_error</span>"; ?>
</span>
</div>
<div class="row">
<span class="cell">MySQL Version (Must be 5 or better)</span>
<span class="cell">
<?php if($mysql_version>5) echo "<span class='green'>$mysql_version - OK!</span>";
else echo "<span class='red'>$mysql_error</span>"; ?>
</span>
</div>
<div class="row">
<span class="cell">PHP Mail Function (Must be enabled)</span>
<span class="cell">
<?php if(empty($mail_error)) echo "<span class='green'>Looks enabled - OK!</span>";
else echo "<span class='red'>$mail_error</span>"; ?>
</span>

</div>
<div class="row">
<span class="cell">PHP Safe Mode (Must be off)</span>
<span class="cell">
<?php if(($safe_mode=="Off")) echo "<span class='green'>Safe mode is Off - OK!</span>";
else echo "<span class='red'>Safe mode is on!</span>"; ?>
</span>
</div>
<div class="row">
<span class="cell">PHP Sessions (Must be enabled)</span>
<span class="cell">
<?php if(empty($session_error)) echo "<span class='green'>Sessions are enabled - OK!</span>";
else echo "<span class='red'>$session_error</span>"; ?></span>
</div>
<div class="row">
<span class="cell">Register Globals (Must be off)</span>
<span class="cell">
<?php if(($register_globals=="Off")) echo "<span class='green'>Register Globals is off - OK!</span>";
else echo "<span class='red'>Register Globals is on!</span>" ?></span>
</div>
</div>
</div>
</div>


<form name="pretest" action="#" method="post" id="pretest">
<?php if($error=="true") echo "Unable to continue with setup due to the errors above outlined in Red";
else echo "<button type='submit' class='button'>Start Setup</button>"; ?>
</form>

</body>
</html>

Download here

View Demo here

AnonymousIan.J.Gough

Did this help you? Please Let me know by commenting below even if it’s just to say “Thanks”

leave a comment

About This Site

Dreams are built from lines of code well it's true!
If you can dream it you can usually code it.

I have learned so much from other people on the Internet and this site is for me to give back some of what i have learned and hope people can now learn from me.
Have fun and surf safely,
Ian.J.Gough

protected by copyscape duplicate content check

Categories


Powered by Banner Bar 125