Add api and usage page
This commit is contained in:
40
index.php
40
index.php
@@ -9,38 +9,40 @@ include "./conversions.php";
|
||||
</head>
|
||||
<body>
|
||||
<div class="inputs">
|
||||
<form action="index.php" method="get">
|
||||
<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="get">
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
$bin = 0;
|
||||
$dec = 0;
|
||||
$hex = 0;
|
||||
$bin = $dec = $hex = 0;
|
||||
$new = false;
|
||||
|
||||
if (!isset($_GET['binary']) ||
|
||||
!isset($_GET['decimal']) ||
|
||||
!isset($_GET['hexadecimal'])) {
|
||||
// Check if GET params are set
|
||||
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 (!isset($_SESSION['bin']) || !isset($_SESSION['dec']) || !isset($_SESSION['hex'])) {
|
||||
$_SESSION['bin'] = $_SESSION['dec'] = $_SESSION['hex'] = 0;
|
||||
}
|
||||
|
||||
if (!$new) {
|
||||
$last_bin = $_SESSION['bin'];
|
||||
$last_dec = $_SESSION['dec'];
|
||||
$last_hex = $_SESSION['hex'];
|
||||
$last_bin = $_SESSION['bin'];
|
||||
$last_dec = $_SESSION['dec'];
|
||||
$last_hex = $_SESSION['hex'];
|
||||
|
||||
if (!$new) {
|
||||
$bin = $_GET['binary'];
|
||||
$dec = $_GET['decimal'];
|
||||
$hex = $_GET['hexadecimal'];
|
||||
}
|
||||
|
||||
// Check if it's a pasted url (all params are passed and aren't 0)
|
||||
if (isset($_GET['binary']) && isset($_GET['decimal']) && isset($_GET['hexadecimal']) &&
|
||||
$_GET['binary'] != 0 && $_GET['decimal'] != 0 && $_GET['hexadecimal'] != 0 &&
|
||||
$bin == $last_bin && $dec == $last_dec && $hex == $last_hex) {
|
||||
$new = true;
|
||||
}
|
||||
|
||||
if (!$new) {
|
||||
if ($bin == 0 && $dec == 0) {
|
||||
$bin = hex_to_binary($hex);
|
||||
$_SESSION['bin'] = $bin;
|
||||
@@ -80,9 +82,7 @@ include "./conversions.php";
|
||||
$hex = binary_to_hex($bin);
|
||||
$_SESSION['hex'] = $hex;
|
||||
} else {
|
||||
$bin = 0;
|
||||
$dec = 0;
|
||||
$hex = 0;
|
||||
$bin = $dec = $hex = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user