简体   繁体   中英

Securing REST API in PHP

All my database related files are in config folder (fetch, post, update, delete). and I'm using ajax on the client side to use that data. my question is how can I secure my API files. I've studded about JWT and I think it is only for user login and signup. I want that when someone opens my api url like: 'http://localhost/config/getPosts.php' they should be authenticated before they can see the posts. I've also used basic auth but it is not secure according to my research.

What you want to do is to create a way to check if the user is currently logged in with JWT (Usually done with a middleware) and if not return a 401 error. Then assign the middleware to those routes so you protect those routes with the JWT check.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM