drjun1994 2014-05-21 22:09
浏览 74
已采纳

隐藏DOM中的数据库属性

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.

  • 写回答

1条回答 默认 最新

  • drflkphi675447 2014-05-21 22:20
    关注

    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)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂