Created
November 4, 2019 07:45
-
-
Save farukgaric/e91beebd4c1c7e57899dfc1857f38647 to your computer and use it in GitHub Desktop.
Simple php jwt response
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| if(!isset($_POST['username']) && !isset($_POST['password']) && empty($_POST['username'] && empty($_POST['password']))){ | |
| header("HTTP/1.1 401 Unauthorized"); | |
| exit; | |
| } | |
| if($_POST['username'] == 'admin' && $_POST['password'] == "admin123"){ | |
| // clear the old headers | |
| header_remove(); | |
| // set the actual code | |
| http_response_code(200); | |
| // set the header to make sure cache is forced | |
| header("Cache-Control: no-transform,public,max-age=300,s-maxage=900"); | |
| // treat this as json | |
| header('Content-Type: application/json'); | |
| // ok, validation error, or failure | |
| header('Status: 200 OK'); | |
| $responseToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJ1c2VybmFtZSI6ImFkbWluIn0.ssum5s-G5F3tcssCXwXymGJpXJ0PT3sgZ0xwXNYMMws"; | |
| echo json_encode([ | |
| 'status' => 200, | |
| 'data' => [ | |
| 'token' => $responseToken | |
| ] | |
| ]); | |
| exit; | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment