Jump to content

hexadecimal id instead of number?


onedumbcoder

Recommended Posts

Is it possible to create a primary key id that is hexadecimal and auto incremental?

 

 

I currently use numbers and I would like to know if it is possible to use hexadecimal id and have the table auto increment it.

 

 

 

Otherwise I was thinking of using a 20 length string who's values would be randomly generate?

 

for sample  id[0] = rand(14), id[1] = rand(14), .... and so on? but i was thinking that would/might lead to problems?

 

 

Link to comment
https://forums.phpfreaks.com/topic/160742-hexadecimal-id-instead-of-number/
Share on other sites

My only question is ... why?

Any integer (decimal) can be represented in HEX form, so why would you bother storing them in hex? And if you think about it... all numbers in any computer system are binary anyway... it's just the user representation that differs to make it more readable.

So again, my question ... why?

here is the issue I am.

 

I have a page where the id of the element is in the

 

url for example lets just say the url is

 

www.somesite.com/viewitem.php?id=1

 

I dont want users to be able to view different items sequentially changing the id

 

for example

 

www.somesite.com/viewitem.php?id=1

www.somesite.com/viewitem.php?id=2

www.somesite.com/viewitem.php?id=3

www.somesite.com/viewitem.php?id=4

....

 

 

There are many reason I have for this, one is I dont want it to give away which items where added last what item came after item 5 lets say.

 

I want to prevent them from being able to determine anything from the id.

 

this is why I think if I that maybe the best way of doing this is by generating a random hex id.

 

 

 

when you create id each have to be unique so there are few ways to do this.

 

You can hash(sha1, md5) the current time and thats the id, hashes look crazy and have no order. But they are lony like 30 characters.

 

Or be simple and just put in the datetime using you own "secret way" like today is 06-03-09 4:40 so the id could be 3060440 and just add like 123456 to it and then you get 423896. Now tell me what date that represents?

 

Since it invloves date and time it will always be different and it will be wierd because time changes. use seconds and then its super cyptic!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.