I have a messages table that auto increments and I simply want to able to capture the auto-incremental ID number and store it along with a randomly generated code. I would then use this code to spit out entire pages. For example, let’s say the users just updated a new message and the auto-increment message ID is 429. I want to be able to store that 429 and add a 5 digit code to the end so that message gets the 429 ID automatically but also has an identifier in its column with a code like, 429mUwIz.
I would then have a public page that would take that code and show the specific message. So if you were to go to http://www.example.com/429mUwIz, it would show you the message entered. I obviously need the 5 randomized generator so users couldn’t directly go to http://www.example.com/1, http://www.example.com/2 and abuse the system.
So what would be the best way to come up with such a code and I know that mysql_insert_id won’t work since I need the ID stored with the insert.
Attached is an example of exactly how Path has created such a system. Their letters are also case-sensitive if that helps.
Thanks.
EDIT: What’s the best way to create this random 5 key code also. Sorry.
You can query for it
This retrieves the next auto increment id … docs for SHOW TABLE STATUS here
And to generate a 5 character random string use
Uses
microtime()andmd5to produce a hash and then grabs a random 5 characters ….. It doesn’t need to be unique as you are using the auto increment id with it …