简体   繁体   中英

simple encode/decode with PHP to avoid passing id that are easy to guess

is there a "simple" way to mask an interger in PHP?

I have /users/1, /users/2...

I want to have something a little bit more fancier like /users/fsdafs3453 to make it hard to guess user ids. it doesn´t need to be super secure is just to avoid having my users switch from user to user just changing the url. I tried with sha1(...) but there´s no way to decode it. thank you!

I have used hashids in some projects. As security is not an issue it works fine in most cases.

https://hashids.org/php/

Another solution a bit more secure is to save a slug or a uid in your database for each user and use this in your request instead of id.

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