Advertisement
Guest User

Untitled

a guest
Aug 20th, 2016
442
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.84 KB | None | 0 0
  1. //// java.php
  2. <?php
  3.     $response = array();
  4.     header("Content-Type:application/json");
  5.     if($_POST){
  6.         $token = $_POST['token'];
  7.         include 'JWTManager.php';
  8.         $check = CheckToken($token,$key);
  9.         if(isset($check["success"]) && $check["success"] == -1){
  10.             $response["success"] = -1;
  11.             $response["message"] = $check["message"];
  12.         }else{
  13.             $response = $check;
  14.         }
  15.     }
  16.     echo json_encode($response);
  17. ?>
  18. //// JWTManager.php
  19. <?php
  20. require_once 'vendor/autoload.php';
  21. use \Firebase\JWT\JWT;
  22. $key = 'cxrrQXzprE';
  23. function GenerateToken($token,$key){
  24.     return JWT::encode($token, $key);
  25. }
  26.  
  27. function CheckToken($jwt,$key){
  28.     try{
  29.         $decoded = JWT::decode($jwt,$key,array('HS256'));
  30.         return (array)$decoded;
  31.     }catch(Exception $e){
  32.         $error = array();
  33.         $error["message"] = $e->getMessage();
  34.         $error["success"] = -1;
  35.         return $error;
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement