Generating IDs for pictures in database and web server with PHP

I'm generating IDs with PHP for images to store the image by ID name on my web server and store its ID in a database.
For example, this image of Queen Elizabeth on Bing has the following URL
https://bing.com/th?id=ALSTUDD054E144F1E7A2A675119C4029373B6E59D884370A650CDB6F5389ACF982A38
The image has an ID of capital letters and numbers.
How are these IDs typically generated? Are they a hash of the image's name? How does it work? Are there any common methods using PHP to generate a similar ID?
Answer
Solution:
An ID can be generated multiple ways.
I think the computationally simplest way would be something like this:
- Have a file that keeps track of the last ID entered. Let this file be empty for now.
- To generate a new ID: if the file is empty, start with an ID of zero. Otherwise, increment the number stored in the file and use the new number as an ID.
- Save the new ID in the file.
To save memory, you could also store the ID as a hexadecimal number with out the 0x part. So, 20,000,000 becomes 1312D00.
You could also use a pseudo-random number generator to generate an ID - just generate a new ID every time you generate an ID that's already been used.
You could even create some "check digits" to ensure the ID being passed to the server is a valid ID; it could be as simple as generating a bunch of digits and summing them together, storing - say - the first digit of the sum as the last digit in the ID.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: zsh: command not found: php
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.