Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 6th Jul 2013, 12:48 AM   #1
Warrior Member
 
Join Date: 2012
Posts: 20
Thanks: 1
Thanked 1 Time in 1 Post
Default
PHP Random string generation help required
Share on: 
fb share twitter share gplus share more share

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.
Iluminada is offline  
Unread 6th Jul 2013, 12:51 AM   #2
Active Warrior
 
bugtrack's Avatar
 
Join Date: 2012
Location: United Kingdom
Posts: 60
Thanks: 0
Thanked 5 Times in 5 Posts
Default
Re: PHP Random string generation help required
Share on: 
fb share twitter share gplus share more share

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
bugtrack is offline  
Unread 6th Jul 2013, 12:55 AM   #3
Warrior Member
 
Join Date: 2012
Posts: 20
Thanks: 1
Thanked 1 Time in 1 Post
Default
Re: PHP Random string generation help required
Share on: 
fb share twitter share gplus share more share

@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
Iluminada is offline  
Unread 6th Jul 2013, 12:59 AM   #4
Active Warrior
 
bugtrack's Avatar
 
Join Date: 2012
Location: United Kingdom
Posts: 60
Thanks: 0
Thanked 5 Times in 5 Posts
Default
Re: PHP Random string generation help required
Share on: 
fb share twitter share gplus share more share

Ok here is a simple code for you.

PHP Code:
session_start();
echo  
substr(session_id(),1,8).rand(); 
bugtrack is offline  
The Following User Says Thank You to bugtrack For This Useful Post:
Unread 6th Jul 2013, 01:04 AM   #5
Warrior Member
 
Join Date: 2012
Posts: 20
Thanks: 1
Thanked 1 Time in 1 Post
Default
Re: PHP Random string generation help required
Share on: 
fb share twitter share gplus share more share

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
Iluminada is offline  
Unread 6th Jul 2013, 01:06 AM   #6
Active Warrior
 
bugtrack's Avatar
 
Join Date: 2012
Location: United Kingdom
Posts: 60
Thanks: 0
Thanked 5 Times in 5 Posts
Default
Re: PHP Random string generation help required
Share on: 
fb share twitter share gplus share more share

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
bugtrack is offline  
Unread 6th Jul 2013, 10:19 AM   #7
Advanced Warrior
War Room Member
 
Brandon Tanner's Avatar
 
Join Date: 2006
Location: USA
Posts: 1,907
Thanks: 236
Thanked 1,377 Times in 676 Posts
Default
Re: PHP Random string generation help required
Share on: 
fb share twitter share gplus share more share

Here's another way to do it...

$randomString = md5(rand());


Brandon Tanner is offline  
Unread 6th Jul 2013, 01:48 PM   #8
Active Warrior
War Room Member
 
Paul Moss's Avatar
 
Join Date: 2013
Location: Florida
Posts: 49
Thanks: 0
Thanked 4 Times in 4 Posts
Default
Re: PHP Random string generation help required
Share on: 
fb share twitter share gplus share more share

For some reason I'm not able to put this in full.

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

Pretty cool answer.
Paul Moss is offline  
Unread 8th Jul 2013, 12:40 PM   #9
Active Warrior
 
Join Date: 2009
Posts: 31
Thanks: 1
Thanked 4 Times in 4 Posts
Default
Re: PHP Random string generation help required
Share on: 
fb share twitter share gplus share more share

Originally Posted by Paul Moss View Post

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.
Rennell Garrett is offline  
Unread 9th Jul 2013, 11:31 AM   #10
www.freetutorial.co
 
Join Date: 2013
Location: India
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default
Re: PHP Random string generation help required
Share on: 
fb share twitter share gplus share more share

<?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
freetutorial is offline  
Unread 9th Jul 2013, 06:51 PM   #11
Warrior Member
 
Join Date: 2012
Posts: 20
Thanks: 1
Thanked 1 Time in 1 Post
Default
Re: PHP Random string generation help required
Share on: 
fb share twitter share gplus share more share

You can geenrate very good random string by session and md5 combination

echo md5(substr(session_id(),0,10));
You can use both the function together and get good string
Iluminada is offline  
Unread 24th Jul 2013, 06:33 AM   #12
SKT Wordpress Themes
War Room Member
 
sktthemes's Avatar
 
Join Date: 2013
Location: Nagpur
Posts: 65
Thanks: 5
Thanked 28 Times in 11 Posts
Default
Re: PHP Random string generation help required
Share on: 
fb share twitter share gplus share more share

Hello

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

sktthemes is offline  
Unread 28th Jul 2013, 10:39 AM   #13
HyperActive Warrior
 
Join Date: 2010
Posts: 267
Thanks: 5
Thanked 6 Times in 6 Posts
Default
Re: PHP Random string generation help required
Share on: 
fb share twitter share gplus share more share

Have a look at tthis page
PHP Randoms - Random Functions To Do Random Numbers, Random Strings, Random Files, & More

Thanks & Regards,
Reach us at dukeduke600@gmail.com.
Web Design| Logo Design | Banner Design | Web Development | Mobile Applications [iPhone/iPad/Android/Windows Phone]
weaveronline is offline  
Unread 13th Aug 2014, 08:12 PM   #14
Jim Riley
 
Join Date: 2011
Location: Canada
Posts: 137
Thanks: 60
Thanked 21 Times in 17 Posts
Default
Re: PHP Random string generation help required
Share on: 
fb share twitter share gplus share more share

This might help you to generate PHP password. You can download the script if required.
PHP Password Generator
JimRiley is offline  
Closed Thread


Bookmarks

Tags
generation, php, random, required, string


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 01:45 AM.