Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Change the header, and get the results as json
- function getResults($result) {
- header("Content-type: application/json", true, 200);
- return json_encode($result, JSON_PRETTY_PRINT);
- }
- // Get forbidden message
- function getForbidden() {
- header("HTTP/1.1 403 Forbidden", true, 403);
- return "<strong>Forbidden</strong>";
- }
- function getFile($file) {
- header("HTTP/1.1 200 OK", true, 200);
- return file_get_contents("index.html");
- }
- // Handle requests
- if ($_POST) {
- // Dummy result object
- $result = array(
- "status" => -1,
- "statusmessage" => "",
- "message" => "No result to display"
- );
- if (isset($_POST['action'])) {
- // Login
- if ($_POST['action'] == "login") {
- if (isset($_POST['username']) && isset($_POST['password'])) {
- $username = $_POST['username'];
- $password = $_POST['password'];
- if ($username == "root" && $password == "toor") {
- $result['status'] = 1;
- $result['statusmessage'] = "success";
- $result['message'] = "Successfully logged in as $username";
- }
- }
- // Register
- } elseif ($_POST['action'] == "register") {
- // handle register mechanism
- } else {
- $result['status'] = -1;
- $result['statusmessage'] = "error";
- $result['message'] = "No such command has been implemented";
- }
- }
- // Print results
- echo getResults($result);
- } elseif ($_GET) {
- echo getFile("index.html");
- } else {
- echo getForbidden();
- }
- // Exit
- die();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement