Advertisement
Guest User

Untitled

a guest
Nov 9th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.59 KB | None | 0 0
  1. <?php
  2.  
  3.     // Change the header, and get the results as json
  4.     function getResults($result) {
  5.         header("Content-type: application/json", true, 200);
  6.         return json_encode($result, JSON_PRETTY_PRINT);
  7.     }
  8.    
  9.     // Get forbidden message
  10.     function getForbidden() {
  11.         header("HTTP/1.1 403 Forbidden", true, 403);
  12.         return "<strong>Forbidden</strong>";
  13.     }
  14.    
  15.     function getFile($file) {
  16.         header("HTTP/1.1 200 OK", true, 200);
  17.         return file_get_contents("index.html");
  18.     }
  19.    
  20.     // Handle requests
  21.     if ($_POST) {
  22.        
  23.         // Dummy result object
  24.         $result = array(
  25.             "status" => -1,
  26.             "statusmessage" => "",
  27.             "message" => "No result to display"
  28.         );
  29.        
  30.         if (isset($_POST['action'])) {
  31.            
  32.             // Login
  33.             if ($_POST['action'] == "login") {
  34.                
  35.                 if (isset($_POST['username']) && isset($_POST['password'])) {
  36.                    
  37.                     $username = $_POST['username'];
  38.                     $password = $_POST['password'];
  39.                    
  40.                     if ($username == "root" && $password == "toor") {
  41.                        
  42.                         $result['status'] = 1;
  43.                         $result['statusmessage'] = "success";
  44.                         $result['message'] = "Successfully logged in as $username";
  45.                        
  46.                     }
  47.                    
  48.                 }
  49.                
  50.             // Register
  51.             } elseif ($_POST['action'] == "register") {
  52.                
  53.                 // handle register mechanism
  54.                
  55.             } else {
  56.                
  57.                 $result['status'] = -1;
  58.                 $result['statusmessage'] = "error";
  59.                 $result['message'] = "No such command has been implemented";
  60.                
  61.             }
  62.            
  63.         }
  64.        
  65.         // Print results
  66.         echo getResults($result);
  67.        
  68.     } elseif ($_GET) {
  69.        
  70.         echo getFile("index.html");
  71.        
  72.     } else {
  73.        
  74.         echo getForbidden();
  75.        
  76.     }
  77.    
  78.     // Exit
  79.     die();
  80. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement