Page 1 of 1

How to make the id with whatever value.

Posted: Wed Mar 25, 2009 11:19 am
by MicroBoy
I want that whenever I submit some informations to database the id would be in whatever value, I'm using id with auto_increment but every time it is 1 2 3... I want to be something like this "sdijds5654dd" or whatever just not so easy like 1 2 3 etc... Meaby I was very unclear:S

Re: How to make the id with whatever value.

Posted: Wed Mar 25, 2009 12:37 pm
by Mark Baker
MicroBoy wrote:I want that whenever I submit some informations to database the id would be in whatever value, I'm using id with auto_increment but every time it is 1 2 3... I want to be something like this "sdijds5654dd" or whatever just not so easy like 1 2 3 etc... Meaby I was very unclear:S
In that case, you'll have to create the ID yourself according to whatever criteria you choose.

But what's wrong with 1, 2, 3.... just because it's "easy" doesn't make it wrong

Re: How to make the id with whatever value.

Posted: Wed Mar 25, 2009 4:25 pm
by MicroBoy
Yes but in my case I need a complicated ID.
Mark Baker wrote:In that case, you'll have to create the ID yourself according to whatever criteria you choose.
Do you have any suggest how to do that? It doesn't metter how that Id would be, just it has to be complicated.

Re: How to make the id with whatever value.

Posted: Wed Mar 25, 2009 4:57 pm
by Mark Baker
MicroBoy wrote:Do you have any suggest how to do that? It doesn't metter how that Id would be, just it has to be complicated.
Personally I wouldn't do it, and can't conceive of any reason for doing so; but if it's absolutely necessary, you could use something like

Code: Select all

$id = sha1(uniqid(rand(), true));
to generate a value.

Re: How to make the id with whatever value.

Posted: Wed Mar 25, 2009 6:26 pm
by MicroBoy
Is sure that every time the value would be other? That the value wouldn't be the same twice?

p.s. I wan't to use this because i'm deleting the news by this value, and if I let the value 1 2 3 etc... someone can delete just by writing a number like 1 2 etc.... Meaby it's a bed idea?

Re: How to make the id with whatever value.

Posted: Wed Mar 25, 2009 7:32 pm
by califdon
Yes, it's a bad idea, as Mark Baker said several times. ID's are never to be used by live human beings! Your application must manage user operations and not reveal system data like record ID's. ID's are for one and only one purpose: to uniquely identify every row in a table. Period. Don't ever try to use them for other reasons, you will get yourself in a world of trouble.

Re: How to make the id with whatever value.

Posted: Thu Mar 26, 2009 4:10 am
by Mark Baker
MicroBoy wrote:Is sure that every time the value would be other? That the value wouldn't be the same twice?
Theoretically, it doesn't guarantee that every ID will be unique, but the probability that it will generate two identical IDs is 1 in 2^63
MicroBoy wrote:p.s. I wan't to use this because i'm deleting the news by this value, and if I let the value 1 2 3 etc... someone can delete just by writing a number like 1 2 etc.... Meaby it's a bed idea?
You don't make your data secure just by trying to confuse potential hackers by making the ID values complex. This is a very bad idea. If you implement proper security, then it doesn't matter if somebody changes the ID value being passed through from a 1 to a 2.
Simply put, ensure that a user is logged in before they can use a delete function, and don't allow them to delete any record unless it's one that they themself have created. This may mean storing the ID of the user that created each record in your database, and if somebody tries to delete a record you check that their user ID is the same that recorded in the database. And you don't need to show the user their own ID, or pass it through in the url, because you maintain it within the session so it can't be modified.

Re: How to make the id with whatever value.

Posted: Thu Mar 26, 2009 10:03 am
by MicroBoy
Thnx a lot both of you. My application will not be used by other persons just by me and some friends and will be installed just in my computer, I just wanted to do that because meaby someone unwillingly will delete.

Re: How to make the id with whatever value.

Posted: Thu Mar 26, 2009 11:15 am
by califdon
Bad ideas are bad ideas, no matter whether they apply to public or private use. Do yourself a huge favor and learn to do things the right way every time. Then later you won't have habits that get you into big trouble.

Re: How to make the id with whatever value.

Posted: Thu Mar 26, 2009 3:51 pm
by MicroBoy
califdon wrote:Bad ideas are bad ideas, no matter whether they apply to public or private use. Do yourself a huge favor and learn to do things the right way every time. Then later you won't have habits that get you into big trouble.
Ok when you have free time, please if you can post a method that you use to delete rows, or that you saw somewhere.

thnx a lot

Re: How to make the id with whatever value.

Posted: Thu Mar 26, 2009 6:58 pm
by califdon
MicroBoy wrote:
califdon wrote:Bad ideas are bad ideas, no matter whether they apply to public or private use. Do yourself a huge favor and learn to do things the right way every time. Then later you won't have habits that get you into big trouble.
Ok when you have free time, please if you can post a method that you use to delete rows, or that you saw somewhere.

thnx a lot
In order to tell you how to do it, I would have to know how your database is organized, what your script is like now, how you want it to appear to your users, how sensitive or important the data is, and a lot more. All that other people can do is explain principles to you. You have to decide how to apply those principles. Otherwise, we are writing your application for you, and most of us are not willing to do that.

Mark Baker gave you some good information in his earlier post:
Mark Baker wrote:Simply put, ensure that a user is logged in before they can use a delete function, and don't allow them to delete any record unless it's one that they themself have created. This may mean storing the ID of the user that created each record in your database, and if somebody tries to delete a record you check that their user ID is the same that recorded in the database. And you don't need to show the user their own ID, or pass it through in the url, because you maintain it within the session so it can't be modified.

Re: How to make the id with whatever value.

Posted: Fri Mar 27, 2009 7:20 am
by MicroBoy
First of all I said that if you have an application that you use to delete rows or if you know where I can find it, it doesn't metter that application will not be for me I will try to correct somethings that I need for me.

Second, at this time I don't want to make my application with User Login ok.

thnx again that you're helping me.