Warrior Forum - The #1 Digital Marketing Forum & Marketplace

Warrior Forum - The #1 Digital Marketing Forum & Marketplace (https://www.warriorforum.com/)
-   Programming (https://www.warriorforum.com/programming/)
-   -   PHP Random string generation help required (https://www.warriorforum.com/programming/810394-php-random-string-generation-help-required.html)

Iluminada 6th July 2013 12:48 AM

PHP Random string generation help required
 
hello people

I am new to php and I just wonder I want combination of random number and random string, how can I generate it using php?

Any help regarding this is highly appreciated.

bugtrack 6th July 2013 12:51 AM

Re: PHP Random string generation help required
 
You can use rand function of php to generate random number and you can take part of the session_id to generate random string , if you combine both of them it will give you required result

Iluminada 6th July 2013 12:55 AM

Re: PHP Random string generation help required
 
@bug thank you for your help but if you dont mind can you give me an example of what you have explain in php code?

Thanks in advance

bugtrack 6th July 2013 12:59 AM

Re: PHP Random string generation help required
 
Ok here is a simple code for you.

PHP Code:

session_start();
echo  
substr(session_id(),1,8).rand(); 


Iluminada 6th July 2013 01:04 AM

Re: PHP Random string generation help required
 
its working fine right now but when i refresh the page first few characters remains same it only get new characters when i close browswer window and reopen it

bugtrack 6th July 2013 01:06 AM

Re: PHP Random string generation help required
 
You can use

PHP Code:

session_regenerate_id(); 

use this code after session_start i hope it will help and your problem will be solved, all the best

Brandon Tanner 6th July 2013 10:19 AM

Re: PHP Random string generation help required
 
Here's another way to do it...

$randomString = md5(rand());

Paul Moss 6th July 2013 01:48 PM

Re: PHP Random string generation help required
 
For some reason I'm not able to put this in full.

Check out this link: http://stackoverflow.com/a/853898

Pretty cool answer.

Rennell Garrett 8th July 2013 12:40 PM

Re: PHP Random string generation help required
 
Quote:

Originally Posted by Paul Moss (Post 8250439)
For some reason I'm not able to put this in full.

Check out this link: How to create a random string using PHP? - Stack Overflow

Pretty cool answer.

This is a nice find. Truely a unique way of generating random stuffs. Thanks for the share.

freetutorial 9th July 2013 11:31 AM

Re: PHP Random string generation help required
 
<?php

function RandomTxt() {
$chars = "thequickbrownfoxjumpsoverthelazydog";
srand((double)microtime()*1000000);
$i = 0;
$pass = '' ;
while ($i <= 10) {
$num = rand() % 33;
$tmp = substr($chars, $num, 1);
$pass = $pass . $tmp;
$i++;
}

return $pass;
}

echo RandomTxt();
?>

above code useful to create random text

Iluminada 9th July 2013 06:51 PM

Re: PHP Random string generation help required
 
You can geenrate very good random string by session and md5 combination

Quote:

echo md5(substr(session_id(),0,10));
You can use both the function together and get good string

sktthemes 24th July 2013 06:33 AM

Re: PHP Random string generation help required
 
Hello

You can use uniqid(); to randomly ganerate numbers/string

weaveronline 28th July 2013 10:39 AM

Re: PHP Random string generation help required
 
Have a look at tthis page
PHP Randoms - Random Functions To Do Random Numbers, Random Strings, Random Files, & More

JimRiley 13th August 2014 08:12 PM

Re: PHP Random string generation help required
 
This might help you to generate PHP password. You can download the script if required.
PHP Password Generator


All times are GMT -6. The time now is 02:05 AM.