I'm creating a simple app to learn some PHP and SQL. To fetch each user's posts, I am using a key called post_id
which auto increments and is also the primary/unique key. At the moment I get every post with this post_id
. If a user were to open up the DOM, they would be able see only their post ID's (no on else's), like so:
<ul>
<li data-id="173">My first post!</li>
<li data-id="174">My second post!</li>
<li data-id="175">My third post!</li>
</ul>
Is it a problem that these data-id's could potentially get very large, very quickly? Is it worth me trying to reformat the database, so each user will get their own set of much smaller IDs:
<ul>
<li data-id="4">My first post!</li>
<li data-id="5">My second post!</li>
<li data-id="6">My third post!</li>
</ul>
The benefit of this I assume means they will be less revealing if someone looks at the source, and perhaps easier for me to code in the long run?
Or is this simply a non-issue? I've never done something like this so any guidance would be much appreciated.
In regards to someone getting the ID from the DOM, and using it for any malicious purpose, this would be bad practice if a user could use a random number to access something they shouldn't. You should use session validation and user logins to prevent accessing posts with an arbitrary number.
The second point you mentioned, about the number growing quickly, is a more interesting topic. Generally numbers in computing in general can be quite large. It depends on what type of column you use to store your number in the database.
For instance, if you choose integer on a 32bit system, and integer is any number from -2147483647 to 2147483647. This means you can have 2147483647 posts before your application cannot have any more. But that's a really large number. Imagine you have 10 posts on your website a second (that's quite a few), that means in a year you will have 315576000 posts. Divide the max integer by that and you get a lifetime of 6.8 years.
However, if you run on a 64bit system, or you choose a column type like "BIGINT" (or similar) you have a much larger number. 64bit systems have a max integer size of 9223372036854775807 (that's 29227102304.5 years of 10 posts a second)