PHP Serial Number Generator PHP March 21st, 2007. I needed to generate roughly 50k unique serials. So I searched the web and found one solution, which I modified slightly and created to fit my needs. Its in PHP and will output a generated comma delimited CSV column1, column2 format (MS Excel will open that up for editing). I am trying to generate a Serial number (function Taken from a Post on this site ) Check in my database if this Serial exist, if it does. PHP - generate serial number. Ask Question 0. Can someone tell me if there's a better way doing this? Php script echoing part of the php instead of what intended. You are not logged in to a Random Code Generator account, which means you can generate up to 1000 codes. If you need to generate more than 1000 codes (up to 250.000 at a time), buy a Random Code Generator account to generate an unlimited amount of codes.
- Php Serial Number Generator Number
- Php Serial Number Generator Download
- Php Serial Number Generator Numbers
- Php Serial Number Generator Code
- Product Serial Number Generator
What’s the best way of generating a unique key, that can’t be guessed easily?
I would like to create a unique key for both account activation and referral purposes, that includes a checksum to help prevent users from easily guessing other users activation or referral keys.
Also, in PHP is it possible to create you own session key?If so, how would you make this unique?
Any help is greatly appreciated.
user826855user826855
7 Answers
AlienWebguyAlienWebguy
You can use uniqid to generate unique IDs. Look at the comments for PHP implementations of UUID (universally unique identifier) generation as well.
Dan GrossmanDan Grossman
AmirshkAmirshk
Just use PHP's build-in function
uniqid()
. See PHP manual.crysxdcrysxd
Other answers have already covered the topic about creating a (pseudo) unique ID, so I only cover how to set your own session id:
The session id in PHP gets automatically generated, but you can set your own. See
session_id()
how to do it.Exemplary it works like this:
hakrehakre
I use this script to randomly generate passwords, you change a couple things around and it will work quite well for what you want.
and for your own session key its pretty simple
Php Serial Number Generator Number
rackemup420rackemup420
Uti MacUti Mac
Not the answer you're looking for? Browse other questions tagged php or ask your own question.
Computers cannot generate random numbers. A machine which works in ones and zeros is unable to magically invent its own stream of random data. However, computers can implement mathematical algorithms which produce pseudo-random numbers. They look like random numbers. They feel like random distributions. But they’re fake; the same sequence of digits is generated if you run the algorithm twice.
Planting Random Seeds
To increase the apparent randomness, most algorithms can be passed a seed — an initialization number for the random sequence. Passing the same seed twice will still generate the same set of random numbers but you can set the seed based on external input factors. The easiest option is the current time but it can be anything; the last keypress, a mouse movement, the temperature, the number of hours wasted on YouTube, or any other factor.
Random PHP Functions
Php Serial Number Generator Download
PHP offers a number of random number functions. The main ones are:
- rand() and the more efficient mt_rand() function. Both return a random number between zero and getrandmax()/mt_getrandmax(). Alternatively, you can pass minimum and maximum parameters:
- srand($seed) and mt_srand($seed) to set a random number seed. This has been done automatically since PHP 4.2.0.
PHP is Too Random!
There are instances when creating a repeatable list of pseudo-random numbers is useful. It’s often used for security or verification purposes, e.g. encrypting a password before it’s transmitted or generating a hash code for a set of data. Unfortunately, PHP can be a little too random. A generated sequence will depend on your hosting platform and version of PHP. In other words, you can’t guarantee the same ‘random’ sequence will be generated twice on two different machines even if the same seed is used.
Php Serial Number Generator Numbers
Rolling Your Own Random Class
Php Serial Number Generator Code
Fortunately, we can write our own random number generator. You’ll find many algorithms on the web, but this is one of the shortest and fastest. First, we initialize our class and a random seed variable:
Product Serial Number Generator
Next we have a seed() function for setting a new seed value. For the algorithm to work correctly, the seed should always be a positive number greater than zero but not large enough to cause mathematical overflows. The seed function takes any value but converts it to a number between 1 and 9,999,999:
Finally, we have our num() function for generating a random number between $min and $max. If no seed has been set it’s initialized with PHP’s own random number generator:
We can now set a seed and output a sequence of numbers:
If you’ve copied this code exactly, you should see the following values no matter what OS or version of PHP you’re running:
Admittedly, repeatable “random” numbers isn’t something you’ll need every day — you’re more likely to require something closer to real randomness and PHP’s functions will serve you better. But there may be occasions when you find this useful.