Advertisement
carlosalvet

api-apiserver.local-card.php

Sep 27th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.22 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. class CardController {
  5.     function credit() {
  6.         $this->helper();
  7.  
  8.         header("Content-Type: text/json; charset=utf-8");
  9.         print json_encode(['credito'=>1572.44]);
  10.     }
  11.  
  12.     function response_unauthorized() {
  13.         header("HTTP/1.1 401 Unauthorized");
  14.         header("Content-Type: text/html; charset=utf-8");
  15.         exit('HTTP/1.1 401 No Autorizado');
  16.     }
  17.  
  18.     function helper() {
  19.         #'SessionID: nonce=a1b2c3,opaque=abc123'
  20.        $sessionid = str_replace('SessionId: ', '', @apache_request_headers()['SessionID']);
  21.         if(!$sessionid) $this->response_unauthorized();
  22.         if(strpos($sessionid, 'nonce') === FALSE) $this->response_unauthorized(); #validar que nonce este en la cadena
  23.        if(strpos($sessionid, 'opaque') === FALSE) $this->response_unauthorized(); #validar que opaque este en la cadena
  24.  
  25.         #TODO Recibir nonce y opaque
  26.        @list($nonce, $opaque) = explode(',', $sessionid);
  27.         $nonce = str_replace('nonce=', '', $nonce);
  28.         $opaque = str_replace('opaque=', '', $opaque);
  29.  
  30.         #TODO verificar nonce y opaque existan
  31.        if(!file_exists("../private/sessions/$nonce-$opaque")) $this->response_unauthorized();
  32.  
  33.     }
  34. }
  35.  
  36.  
  37. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement