Go to PHP-JWT Library
A simple library to encode and decode JSON Web Tokens (JWT) in PHP
This is encoded and decode methods
Download this repository
Paste the repository into the third_party folder of the project
Extract zip file
This is custom library for user authorization
In which the PHP-JWT library is include
This function generate user token
And this function validate user token
There is also a function that will later do it
By this name we have to create a library in our project
And have to paste the complete library
Load Authorization Library
We need to create a config file (jwt.php)
To create JWT Secure Key and JWT Algorithm Type
Generate a user token
Pass user data in generate function
Store user's data in token variable
user token successfully created
Using this function, you can decode user data from token
Decode user token
User token not received
We have to send a token to the header (Authorization)
Add Authorization header
We received the user's data from the decode of the token
We also need to add token time to token data
We can also set the token expiry time
And also can set the header
Không có nhận xét nào:
Đăng nhận xét