In: Computer Science
<?php
session_start();
if (!isset($_GET['action']))
{
$_SESSION["R"] = 0;
$_SESSION["G"] = 0;
$_SESSION["B"] = 244;
}
function checkLimit(int $a)
{
if ($a >= 0 && $a <= 255)
{
return True;
}
return False;
}
if (isset($_GET['action']))
{
if ($_GET['action'] == 'R+')
{
if (checkLimit($_SESSION["R"] + 2))
{
$_SESSION["R"] = $_SESSION["R"] + 2;
}
}
elseif ($_GET['action'] == 'G+')
{
if (checkLimit($_SESSION["G"] + 2))
{
$_SESSION["G"] = $_SESSION["G"] + 2;
}
}
elseif ($_GET['action'] == 'B+')
{
if (checkLimit($_SESSION["B"] + 2))
{
$_SESSION["B"] = $_SESSION["B"] + 2;
}
}
elseif ($_GET['action'] == 'R-')
{
if (checkLimit($_SESSION["R"] - 2))
{
$_SESSION["R"] = $_SESSION["R"] - 2;
}
}
elseif ($_GET['action'] == 'G-')
{
if (checkLimit($_SESSION["G"] - 2))
{
$_SESSION["G"] = $_SESSION["G"] - 2;
}
}
else
{
if (checkLimit($_SESSION["B"] - 2))
{
$_SESSION["B"] = $_SESSION["B"] - 2;
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Colors</title>
<link rel="stylesheet" href="../../lit/genstyle.css" type="text/css">
<style>
div.formcont { text-align: center; }
div.ctlrow { text-align: center; width: 100%; height: 2.5em; }
div.ctlrow div { display: inline-block; }
form input { text-align: center; }
form input.direction { width: 3em; height: 100%; }
form input.pct { width: 3em; height: 50%; }
form input.set { width: auto; height: 50%; }
div.setarea { height: 3em; }
div.setarea div { height: 1em; padding-top: 1em; }
.red { background-color: rgb(90%,50%,50%); }
.green { background-color: rgb(50%,90%,50%); }
.blue { background-color: rgb(50%,50%,90%); }
div.colblock { width: 50%; height: 2em;
margin-left: auto; margin-right: auto; margin-top: 3em;
text-align: center; padding-top: 1em;
}
</style>
</head>
<body>
<h1>Colors</h1>
<form method="GET" action="">
<div class="formcont">
<div class="ctlrow">
<input type="submit" class="direction red" name="action" value="R+">
<input type="submit" class="direction green" name="action" value="G+">
<input type="submit" class="direction blue" name="action" value="B+">
<input type="submit" class="direction red" name="action" value="R-">
<input type="submit" class="direction green" name="action" value="G-">
<input type="submit" class="direction blue" name="action" value="B-">
</div>
<div class="colblock" style="background-color: rgb(<?php echo $_SESSION["R"]; ?>, <?php echo $_SESSION["G"]; ?>, <?php echo $_SESSION["B"]; ?>); color: black"> RGB(<?php echo $_SESSION["R"]; ?>, <?php echo $_SESSION["G"]; ?>, <?php echo $_SESSION["B"]; ?>)</div>
</div>
</form> </body>
</html>