How to make the id with whatever value.
Moderator: General Moderators
How to make the id with whatever value.
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
-
Mark Baker
- Forum Regular
- Posts: 710
- Joined: Thu Oct 30, 2008 6:24 pm
Re: How to make the id with whatever value.
In that case, you'll have to create the ID yourself according to whatever criteria you choose.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
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.
Yes but in my case I need a complicated ID.
Do you have any suggest how to do that? It doesn't metter how that Id would be, just it has to be complicated.Mark Baker wrote:In that case, you'll have to create the ID yourself according to whatever criteria you choose.
-
Mark Baker
- Forum Regular
- Posts: 710
- Joined: Thu Oct 30, 2008 6:24 pm
Re: How to make the id with whatever value.
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 likeMicroBoy 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.
Code: Select all
$id = sha1(uniqid(rand(), true));Re: How to make the id with whatever value.
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?
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.
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.
-
Mark Baker
- Forum Regular
- Posts: 710
- Joined: Thu Oct 30, 2008 6:24 pm
Re: How to make the id with whatever value.
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^63MicroBoy wrote:Is sure that every time the value would be other? That the value wouldn't be the same twice?
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.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?
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.
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.
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.
Ok when you have free time, please if you can post a method that you use to delete rows, or that you saw somewhere.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.
thnx a lot
Re: How to make the id with whatever value.
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.MicroBoy wrote:Ok when you have free time, please if you can post a method that you use to delete rows, or that you saw somewhere.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.
thnx a lot
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.
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.
Second, at this time I don't want to make my application with User Login ok.
thnx again that you're helping me.