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
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?

Link to comment
Share on other sites

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.

 

 

 

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.