With online PHP software; your software code is safe. you will not distribute it, it is easy to integrate with your site. simple to use
It does not need installation to run. Here is an example of the Hypochlorite Dilution Calculator Source Code.
- Download the source code.
- See it works online – the English version
- See it works online – the Arabic version
About online PHP software
- Online software is easy to use and does not need installation to run
- Your software and your code will be safe since you will not distribute them to the final user
- Your software will be easy to integrate with your site
Introduction to Hypochlorite Dilution Calculator (Online PHP Software)
- We use sodium hypochlorite solution at home, swimming water disinfecting, poultry production plants & many more.
- Its most known trade name of it is Clorox.
- Many small plants buy the concentrated solutions in bulk for diluting and packing.
- This calculator is for providing online calculations of the diluting.
Using Hypochlorite Dilution Calculator (Online PHP Software)
- Decide what concentration you want to produce example 4%w/w
- Get the concentration of the stock solution you have.
- Go to the online page for the calculation Online calculator
- Enter your values then press calculates
- the online calculator will use AJAX so the page will display the result without reloading it.
- The webpage will send all the input data to a PHP script that will make the calculation.
Point of Interest in Online PHP Software:
This article discusses the following technique:
- How to build simple online software that you can run on free hosting.
- Simple implantation of Ajax
- Testing your software on your PC
Hosting requirements for Online PHP Software:
- Free or paid hosting account
- We need no database for this software
- The hosting should support PHP.
Why PHP?
- It is the most server-side script available on the webserver even on free plans
- We can run it on both Windows and Unix server
Testing your code locally
To test your code locally, you will need a web server with PHP support.
List of some easy-to-use servers with PHP support by default.
- Uniform Server Zero: Uniform Zero takes a fresh look at Apache, MySQL, PHP, and Perl portability. It has a power full control panel.
- XAMPP: It is a very common Apache-based web server with PHP support
- Server2Go: Portable Apache-based web server with PHP support. It could run on CD.
- AppServ
- USBWebserver
- WampServer
List of some easy-to-use servers you should add PHP support by additional software.
- Small HTTP server lightweight, powerful, multi-functional webserver.
- IIS: To add PHP support to IIS, just install PHP for IIS
How does this application work?
- This application depends on a table of concentrations in different units and the density of the sodium hypochlorite solution. It contains also required excess sodium hydroxide for each concentration.
- To calculate the quantity of water needed to dilute 8% w/w solution to be 4% solution as an example.
- We search in the table for the input and output chlorine weight percentage and the density.
- If we do not find the concentration we will calculate it depending on the nearest concentration
//Online PHP Software
//This function will search for a concentration
//$var: value to be searched
//$field:unit of the value
function searchit($var, $field){
global $hypochlorite_table;
//array contains the data table of chlorine concentrations
//and density and reqiured sodium hydroxide
global $precision;
//precision for each field in the $hypochlorite_table array
$var=round($var,$precision[$field]);
if ( is_numeric ( $var )) $var = (trim($var) == '')? 0 :$var; else $var = 0;
for ($index = 0; $index < count($hypochlorite_table); $index++) {
if($var == $hypochlorite_table[$index][$field]){
return outputrow($index);
}elseif($var < $hypochlorite_table[$index][$field]){
if(!$index) return outputrow($index);
$delta = ($var-$hypochlorite_table[$index-1][$field])
/($hypochlorite_table[$index][$field]-$hypochlorite_table[$index-1][$field]);
return outputrow($index,$delta);
}
}
return false;
}
function outputfield($field,&$row,$index,$delta=0){
global $hypochlorite_table,$precision;
if($delta==0){
$row[$field]= round($hypochlorite_table[$index][$field],
$precision[$field]);
}else{
$row[$field]=round(
$hypochlorite_table[$index-1][$field]
+ $delta*($hypochlorite_table[$index][$field]
- $hypochlorite_table[$index-1][$field])
, $precision[$field]);
}
}
function outputrow($index,$delta=0){
$row=array();
outputfield(ClWV ,$row,$index,$delta);
outputfield(d ,$row,$index,$delta);
outputfield(dChange ,$row,$index,$delta);
outputfield(ClWW ,$row,$index,$delta);
outputfield(ClDegrees,$row,$index,$delta);
outputfield(NaOClWV ,$row,$index,$delta);
outputfield(NaOClWW ,$row,$index,$delta);
outputfield(NaOH ,$row,$index,$delta);
outputfield(dNone ,$row,$index,$delta);
return $row;
}
here is a part of the table used in our Online PHP Software
Cl %W/V | Cl% | Chlorometric Degrees °Cl |
NaOCl % W/V | NaOCl% | Required excess of NaOH % W/W |
Specific Gravity change when adding 1% NaOH |
Specific Gravity With required excess of NaOH |
Specific Gravity Without NaOH |
0.0% | 0.0% | 0.0 | 0.0% | 0.0% | 0.25% | 0.012 | 1.001 | 0.998 |
2.5% | 2.4% | 8.0 | 2.6% | 2.5% | 0.36% | 0.044 | 1.041 | 1.025 |
5.0% | 4.6% | 16.0 | 5.2% | 4.9% | 0.47% | 0.028 | 1.076 | 1.063 |
5.5% | 5.1% | 17.6 | 5.8% | 5.3% | 0.49% | 0.027 | 1.083 | 1.070 |
6.0% | 5.5% | 19.2 | 6.3% | 5.8% | 0.51% | 0.024 | 1.089 | 1.077 |
6.5% | 5.9% | 20.8 | 6.8% | 6.2% | 0.53% | 0.023 | 1.096 | 1.084 |
7.0% | 6.3% | 22.4 | 7.3% | 6.7% | 0.55% | 0.022 | 1.103 | 1.091 |
7.5% | 6.8% | 24.0 | 7.9% | 7.1% | 0.57% | 0.019 | 1.109 | 1.098 |
8.0% | 7.2% | 25.6 | 8.4% | 7.5% | 0.59% | 0.019 | 1.116 | 1.105 |
Storing table data in the array:
- There are 3 data fields and the other fields are calculated fields.
- I store the data fields in the array
// Online PHP Software $hypochlorite_table =array( array(00.0, 1.001, 0.012), array(01.0, 1.020, 0.064), array(01.5, 1.027, 0.053), array(02.0, 1.034, 0.050), array(02.1, 1.035, 0.049), array(02.5, 1.041, 0.044), array(02.6, 1.043, 0.041), ........
- I define fields constants
$fields=array( 0=>'ClWV', //Cl(%w/v): weight of chlorine in 100 ml of the solution 1=>'d', //Specific Gravity of Sodium Hypochlorite solution that //contains default required excess of Sodium Hydroxide 2=>'dChange', //Specific Gravity change when adding 1% NaOH 3=>'ClWW', //Cl%= ClWV /d 4=>'ClDegrees', //°Cl Chlorometric Degrees = = 3.2 * ClWV 5=>'NaOClWV', //NaOCl% w/v: weight of Sodium Hypochlorite in 100 ml of the solution 6=>'NaOClWW', //NaOCl%: weight of Sodium Hypochlorite in 100 g of the solution 7=>'NaOH', //NaOH%: Default required excess of Sodium Hydroxide for //this concentration of hypochlorite=0.25+ClWW*0.75/16 8=>'dNone' //Specific gravity of Sodium Hypochlorite solution that //does not contain any excess of Sodium Hydroxide ); foreach ($fields as $key => $value) define($value,$key);
- Then I store the calculated fields in the array for easy searching.
- I wrote an Html page that will be the interface of the application
Using AJAX to call PHP data in Online PHP Software
Once the user fills the form and presses calculate button, it will call AjaxRefresh
function.
This function will do the following:
- Store all form data in string
- Create XMLHttpRequest object
- Create a function that will handle the AJAX response
- Open XMLHttpRequest object and send the data
function AjaxRefresh(){
var q = 'ajax.php' + '?id=' +
'&CIn=' + CIn.value +
'&COut=' + COut.value +
'&dIn=' + dIn.value +
'&lang=' + lang.value +
'&NaOHIn=' + NaOHIn.value +
'&QOut=' + QOut.value +
'&UnitIn=' + UnitIn.value +
'&UnitInAr=' + UnitInAr.value +
'&UnitOut=' + UnitOut.value +
'&UnitOutAr=' + UnitOutAr.value +
'&UnitQOut=' + UnitQOut.value +
'&UnitQOutAr=' + UnitQOutAr.value ;
var xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState===4 && xmlhttp.status===200)
var pairs = xmlhttp.responseText.split('&');
for(i=0;i<pairs.length;i++){
var pair = pairs[i].split('=');
var element = document.getElementById(pair[0]);
if(element===null){
}else{
try{element.innerHTML = pair[1].trim();}catch(e){};
try{element.value = pair[1].trim();}catch(e){};
};
};
};
xmlhttp.open("GET",q,true);
xmlhttp.send();
}
The PHP script will send the Html elements ids with their new values