Jump to content

random number?


RaythMistwalker

Recommended Posts

How would i get php to randomly select an 8 digit number from 00000000 to 99999999?

 

I need this for my user recognition, when a user logs in a random number will be generated and saved to the database, this way if a hacker gets in using userid the system will remove them if they don't have the same 8 digit code.

Link to comment
https://forums.phpfreaks.com/topic/187149-random-number/
Share on other sites

$num = strintf("%08s", (rand(0, 99999999));

 

is i change the %08s to %16s and add 8 more 9's would that be correct syntax for a 16 digit number?

 

No, it wouldn't - the '0' is the character to be padded. Also, I had a minor typo which I fixed in my previous post.

 

$num = strintf("%016s", (rand(0, 9999999999999999));

 

OR

 

$num = str_pad(rand(1, 9999999999999999), 16, '0', STR_PAD_LEFT);

 

Link to comment
https://forums.phpfreaks.com/topic/187149-random-number/#findComment-988285
Share on other sites

I need this for my user recognition, when a user logs in a random number will be generated and saved to the database, this way if a hacker gets in using userid the system will remove them if they don't have the same 8 digit code.

 

Or if a hacker gets in they will be able to prevent the user from logging in and changing their password.  A savvy hacker could even log in as a user and then use wget to send requests to your server on a timer so the session never ends.  Then the legitimate user would be locked out permanently.

Link to comment
https://forums.phpfreaks.com/topic/187149-random-number/#findComment-988295
Share on other sites

I need this for my user recognition, when a user logs in a random number will be generated and saved to the database, this way if a hacker gets in using userid the system will remove them if they don't have the same 8 digit code.

 

Or if a hacker gets in they will be able to prevent the user from logging in and changing their password.  A savvy hacker could even log in as a user and then use wget to send requests to your server on a timer so the session never ends.  Then the legitimate user would be locked out permanently.

 

ATM the users don't have access to password changing and all the users atm are my close friends if the pass changed could just ask me what it is and i can sort it.

 

Is there a way to automatically expire the 8/16 digit number if it is set as $_SESSION['random_id']

Link to comment
https://forums.phpfreaks.com/topic/187149-random-number/#findComment-988396
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.