Reputation: 6765
When I store some items in a table and then want to have a URL connected to each item I just have something like mywebsite.com/item/132 This will display info about the 132nd item in the items table. Is it bad to have it like this? Should I make it have something like youtube where there are a random set of characters for each item? What is the best way doing that?
Just store the items as usual numbers in the table and then a URL looks more like this?mywebsite.com/item/a19kgjy
Then a PHP script "decrypts" a19kgjy and gets a number which is used to get the correct item from the database?
Will this make everything much slower?
Upvotes: 1
Views: 95
Reputation: 9221
I think this is more related to a security/data protection question. It's really depends on whether you want it easily accessible by others or not. Sometimes the number is so sensitive where it's better to use the hash key, for example let's say transaction_id, or user_id, where you are exposing to others how many transaction your business having a day or how many users your system having, which could indirectly lead to some vulnerability. But if you want to implement the hash approach, I would recommend you to generate the random hash during the data insertion, rather than using the decryption approach during query. That would save you some processing power. But remember to index the hash field for the table. Anyhow, either a number or a hash is not really a search engine friendly url.
Upvotes: 1
Reputation: 263803
It's bad because you are adding extra work for the server to sort. Why not create a table something like this?
CREATE TABLE myTable
(
ID int AUTO_INCREMENT,
httpLink varchar(max)
)
in this case, you will only sort the ID
Upvotes: 2