Last active
July 11, 2025 14:10
-
-
Save sunmeat/91495fd4a45c64b679916085b3808aa7 to your computer and use it in GitHub Desktop.
client server request (backend PHP demo, get html)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://www.sunmeat.site/aspnet/webdemo/calc.html: | |
<html> | |
<head> | |
<meta charset="UTF-8" /> | |
</head> | |
<body bgcolor="#aab7ab"> | |
<h2 align="center">Калькулятор</h2> | |
<form action="calc.php" method="get"> | |
<table align="center" cellspacing="9"> | |
<tr> | |
<td colspan="3">Первое число:</td> | |
<td colspan="3"><input type="text" name="num1" value="0" /></td> | |
</tr> | |
<tr> | |
<td colspan="3">Второе число:</td> | |
<td colspan="3"><input type="text" name="num2" value="0"/></td> | |
</tr> | |
<tr> | |
<td><input type="radio" name="operation" value="plus"> + </input></td> | |
<td><input type="radio" name="operation" value="minus"> - </input></td> | |
<td><input type="radio" name="operation" value="multiply"> * </input></td> | |
<td><input type="radio" name="operation" value="divide"> / </input></td> | |
</tr> | |
<tr> | |
<td colspan="4" align="center"><input type="submit" /></td> | |
</tr> | |
</table> | |
</form> | |
</body> | |
</html> | |
=================================================================================================================== | |
http://www.sunmeat.site/aspnet/webdemo/calc.php: | |
<html> | |
<head> | |
</head> | |
<body bgcolor="#aab7ab"> | |
<h2>Результат:</h2> | |
<h1> | |
<?php | |
$num1 = $_GET["num1"]; | |
$num2 = $_GET["num2"]; | |
if ( !is_numeric($num1) || !is_numeric($num2) ) | |
{ | |
echo "Необходимо ввести два числа!"; | |
return; | |
} | |
if (!isset($_GET["operation"])) | |
{ | |
echo "Что вообще Вы хотели сделать с числами?"; | |
return; | |
} | |
$operation = $_GET["operation"]; | |
switch ($operation) | |
{ | |
case "plus": | |
echo($num1 + $num2); | |
break; | |
case "minus": | |
echo($num1 - $num2); | |
break; | |
case "multiply": | |
echo($num1 * $num2); | |
break; | |
case "divide": | |
if ($num2 == 0) | |
echo "А Вы знали, что на ноль делить нельзя?"; | |
else | |
echo($num1 / $num2); | |
break; | |
} | |
?> | |
</h1> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment