Upload
This commit is contained in:
111
index.php
Normal file
111
index.php
Normal file
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
include "./conversions.php";
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<link rel="stylesheet" href="./style.css">
|
||||
<title>HexDecBin Calc</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="inputs">
|
||||
<form action="index.php" method="get">
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
$bin = 0;
|
||||
$dec = 0;
|
||||
$hex = 0;
|
||||
$new = false;
|
||||
|
||||
if (!isset($_GET['binary']) ||
|
||||
!isset($_GET['decimal']) ||
|
||||
!isset($_GET['hexadecimal'])) {
|
||||
$new = true;
|
||||
}
|
||||
|
||||
if (!isset($_SESSION['bin']) ||
|
||||
!isset($_SESSION['dec']) ||
|
||||
!isset($_SESSION['hex'])) {
|
||||
$_SESSION['bin'] = 0;
|
||||
$_SESSION['dec'] = 0;
|
||||
$_SESSION['hex'] = 0;
|
||||
}
|
||||
|
||||
if (!$new) {
|
||||
$last_bin = $_SESSION['bin'];
|
||||
$last_dec = $_SESSION['dec'];
|
||||
$last_hex = $_SESSION['hex'];
|
||||
|
||||
$bin = $_GET['binary'];
|
||||
$dec = $_GET['decimal'];
|
||||
$hex = $_GET['hexadecimal'];
|
||||
|
||||
if ($bin == 0 && $dec == 0) {
|
||||
$bin = hex_to_binary($hex);
|
||||
$_SESSION['bin'] = $bin;
|
||||
$dec = hex_to_decimal($hex);
|
||||
$_SESSION['dec'] = $dec;
|
||||
$_SESSION['hex'] = $hex;
|
||||
} else if ($bin == 0 && $hex == 0) {
|
||||
$bin = decimal_to_binary($dec);
|
||||
$_SESSION['bin'] = $bin;
|
||||
$_SESSION['dec'] = $dec;
|
||||
$hex = decimal_to_hex($dec);
|
||||
$_SESSION['hex'] = $hex;
|
||||
} else if ($dec == 0 && $hex == 0) {
|
||||
$_SESSION['bin'] = $bin;
|
||||
$dec = binary_to_decimal($bin);
|
||||
$_SESSION['dec'] = $dec;
|
||||
$hex = binary_to_hex($bin);
|
||||
$_SESSION['hex'] = $hex;
|
||||
}
|
||||
else {
|
||||
if ($bin == $last_bin && $dec == $last_dec && $hex != $last_hex) {
|
||||
$bin = hex_to_binary($hex);
|
||||
$_SESSION['bin'] = $bin;
|
||||
$dec = hex_to_decimal($hex);
|
||||
$_SESSION['dec'] = $dec;
|
||||
$_SESSION['hex'] = $hex;
|
||||
} else if ($bin == $last_bin && $hex == $last_hex && $dec != $last_dec) {
|
||||
$bin = decimal_to_binary($dec);
|
||||
$_SESSION['bin'] = $bin;
|
||||
$_SESSION['dec'] = $dec;
|
||||
$hex = decimal_to_hex($dec);
|
||||
$_SESSION['hex'] = $hex;
|
||||
} else if ($dec == $last_dec && $hex == $last_hex && $bin != $last_bin) {
|
||||
$_SESSION['bin'] = $bin;
|
||||
$dec = binary_to_decimal($bin);
|
||||
$_SESSION['dec'] = $dec;
|
||||
$hex = binary_to_hex($bin);
|
||||
$_SESSION['hex'] = $hex;
|
||||
} else {
|
||||
$bin = 0;
|
||||
$dec = 0;
|
||||
$hex = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
<div>
|
||||
<label for="binary">Binary: </label>
|
||||
<input type="text" id="binary" name="binary" value="<?php echo $bin; ?>">
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="decimal">Decimal: </label>
|
||||
<input type="text" id="decimal" name="decimal" value="<?php echo $dec; ?>">
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="hexadecimal">Hexadecimal: </label>
|
||||
<input type="text" id="hexadecimal" name="hexadecimal" value="<?php echo $hex; ?>">
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<input class="submit" type="submit">
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user