Can anyone suggest a versatile PHP encrypt/decrypt algorithm that encrypts in the following way:
- it’s fast
- it’s short, similar to YouTube’s video ids
- can be used as a valid id (an elements attribute)
- can be used as part of a URL safely
Security is not the primary concern here. I’m just wanting to prevent the casual “hacker” from easily accessing certain pages by changing the URL (e.g. http://www.domain.com/?id=1 can easily be changed to http://www.domain.com/?id=2).
If you really really really want to encrypt your primary key (Highly inefficient, will explain later) then use
Where row[‘id’] is your primary key. This creates a url/html safe 6 character string, all will be unique (kind of, see below).
Now. This is why you should NOT do this.
For everyone else USE THIS if you want efficiency
I have the script to create the unique id
I use a mysql database to store previously used id’s, you could use any other kind of database to store the Id’s.
Using this code you have ONE step client-side, to get the row where id then you receive the row[‘rl’].
Please read up on program efficiency and take a look at the documentation for mysql, do so and you will get more happy clients 🙂