我试图编码一个PHP应用程序的消息ID,我无法找到明确的描述如何这样做。
基本上我有一个网址例如 - http://www.mymessager.com?messageID=1234
我想让系统对url的消息ID进行编码,但不要在数据库中对其进行更改,例如 - http://www.mymessager.com?messageID=38927648726894762345768
我该如何做这样的事情,以便如果有人转到编码的url,php将在地址栏中显示http://www.mymessager.com?messageID=38927648726894762345768 ,但脚本会将消息1234从数据库中拉出来?
我知道那里有类似的问题,但我还没有找到一个谈论我想做什么的人(主要是清理网址)。
I am trying to encode the message id of a php application and I cannot find a clear description on how to do so.
Basically I have a url for example - http://www.mymessager.com?messageID=1234
I want to have the system encode the message id for the url but do not change it in the database, for example - http://www.mymessager.com?messageID=38927648726894762345768
How can I do such a thing so that if someone goes to the encoded url the php will display http://www.mymessager.com?messageID=38927648726894762345768 in the address bar, but the script will pull message 1234 out of the database?
I know there have been similar questions out there, but I have not found one that talks about what I want to do (mostly is to clean the url).
最满意答案
这样做是为了避免其他用户使用messageID = 4321等方式打开其他用户的私人信息? 因为这样就没办法走了!
您应该检查是否允许打开邮件的用户这样做。
如果这些消息是非私人的,并且你不想让人们通过修改数字来更多地查看消息。 然后,您可以向数据库添加一个'messageKey'字段并设置指定长度的随机字符串。 示例http://www.mymessager.com?messageKey=jadg23sf34lhs
现在只需在数据库中搜索具有该messageKey的消息即可。 请记住确保messageKey是唯一的。
通过这种方式,您还可以将messageKey设置为易于记忆的内容,或者SEO也许很友好。 只要它是独一无二的。
Is this to avoid other users to open up other users private messages with messageID=4321 and so on? Because then this way is no way to go!
You should check that the user that is opening a message is actually allowed to do so.
If the messages is non private, and you just don't wan't people to incrementially view messages by modifying the number. Then you could add a 'messageKey' field to the database and setting random strings of a specified length. Example http://www.mymessager.com?messageKey=jadg23sf34lhs
Now just search in the DB for messages with that messageKey. Just remember to make sure that the messageKey is unique.
In this way you could also set the messageKey to something easy to remember, or SEO perhaps friendly. As long as it's unique.
更多推荐
发布评论