So for our project we design a web server by using Raspberry Pi. To do this it needs scripting but it’s very different from Linux scripting, in Raspberry Pi it uses the PHP method it’s another programming language but it is called a “server-side scripting”. A server-side scripting is where you create a web design which it involves scripting and HTML source code. In other words the source code from the user request to the server website it is being handled by the script that we are making on the server-side before the server responds to the user’s request.

web server

So for the first part I just helped out with the case command so that both numbers can perform out correctly. So for the coding this where you will input two numbers. Once you input the two numbers you would want to calculate select the options add, subtract, multiply, divide, power, square root, sine, cosine or tangent.

<html>

<head>

<title>Calculator</title>

</head>

<body>

 

<!- -background color- ->

<body bgcolor=”#2EEEF7”>

<!- -First php scripting code to ask user for input and pick operation- ->

<?php

/*the following uses the getfunction to get the operation,

The first number, second number, and the result

*/

$op = $_GET[ ‘submit’ ]; //operation

$num1 = $_GET[‘num1’]; //1st number

$num1 = $_GET[‘num2’]; //2nd number

$result = $_GET [‘result’], //result

 

//switch function is used to select the operands

switch($op)

{

//addition

case ‘plus’: $result=$num1+$num2;

break;

//subtraction

case ‘subtract’: $result=$num1-$num2;

break;

//multiplication

case ‘multiply’: $result=$num1*$num2;

break;

//division

case ‘divide’: $result=$num1/$num2;

break;

//power

case ‘x^y’: $result=pow($num1,$num2);

break;

//square root

case ‘sqrt’: $result=sqrt($num1);

break;

//sine

case ‘Sine’: $result=sin($num1);

break;

//cosine

case ‘Cosine’: $result=cos($num1);

break;

//tangent

case ‘Tangent’: $result=sin($num1);

break;

}//end of switch

 

The second part my partner did this of the coding which are creates buttons. These buttons will appear on the website created so when inputting the two numbers then choose either to add, subtract, multiply, divide, power, square root, sine, cosine, or tangent.

//creation of asking user for inputs and buttons for operands

//echo <<<buttons_input

<hl>Simple Calculator</hl>

*Note*

<br>//new line

sqrt, sine, cosine, and tangent uses the

first number entered to perform operation

<br>br>

<form method=”GET” action=”index.php”>//outputs the same page

enter the first number

//creates a input to ask user for first number

<input type=”text” name=”num1” value= “$num1”><br/>

enter second number

//creates a input to ask user for second number

<input type=”text” name=”num2” value= “$num2”><br/>

result

//creates a input to display result

<input type=text” name=”result” value= “$result”><br/>

<br>Basic</br>

//creation of buttons for operands of +, – ,*, /, x^y, sqrt, sine, cosine, tangent

<input type=”submit” name = “submit” value=”plus”>

<input type=”submit” name = “submit” value=”subtract”>

<input type=”submit” name = “submit” value=”multiply”>

<input type=”submit” name = “submit” value=”divide”>

<br>Exponential</br>

<input type=”submit” name = “submit” value=”x^y”>

<input type=”submit” name = “submit” value=”sqrt”>

<br>Trigonometry</br>

<input type=”submit” name = “submit” value=”Sine”>

<input type=”submit” name = “submit” value=”Cosine”>

<input type=”submit” name = “submit” value=”Tangent”>

</form>//end of form

buttons_input

?><! – – end of first script – ->

 

For the last script code I did this part this will show the result that you have chosen and will appear on the prompter of the web site created. Using if statements we assign the op variable to the operation for each of the operations created and then using echo output the operation performed for each of these when the specified button is pushed.

<! – – Second scripts just outputs the operation in text using if statement

<?php

/*using if statements we assign the op variable to the operation

for each of the operations created and then using echo output the

operation performed for each of these when the specified button is pushed

*/

if($op==’plus’)

{

echo $num1, “ + “, $num2, “ = “, $result;

}

if($op==’subtract’)

{

echo $num1, “ – “, $num2, “ = “, $result;

}

if($op==’multiply’)

{

echo $num1, “ * “, $num2, “ = “, $result;

}

if($op==’divide’)

{

echo $num1, “ / “, $num2, “ = “, $result;

}

if($op==’x^y’)

{

echo $num1, “ ^ “, $num2, “ = “, $result;

}

if($op==’sqrt’)

{

echo “sqrt(“,$num1,”)”, “ = “, $result;

}

if($op==’Sine’)

{

echo “Sine(“,$num1,”)”, “ = “, $result;

}

if($op==’Cosine’)

{

echo “Cosine(“,$num1,”)”, “ = “, $result;

}

if($op==’Tangent’)

{

echo “Tangent(“,$num1,”)”, “ = “, $result;

}

?><! – -end of second script- ->

</body>

</html>