Welcome Guest, Not a member yet? Register   Sign In
Randomly generated string seems to be the same if functions are called at very similar times
#3

[eluser]Dandy_andy[/eluser]
Here is the code for the string_generate:-
Code:
//generate random string for filename and path
public function string_generate() {

  $chars = "abcdefghijklmnopqrstuvwxyz0123456789";
  $size = strlen($chars);
  $string = '';  
  for ($i = 0; $i < 15; $i++) {  
  $string .= $chars[rand(0, $size - 1)];  
   }
  return $string;

}

I can see that the rand() function will be time based and could generate the same string if images are uploaded at the same time. In fact, on testing, the images with the same paths are ones which have exactly the same time in miliseconds as each other. I need to have the images in random folders to avoid any chance of people people able to find out where particular images are stored. What I am doing now is to add an additional few characters onto the end of the string that are user specific so that if images are uploaded at the same time, then chance of them having the same filename is very very slim.

Thanks for your comment.


Messages In This Thread
Randomly generated string seems to be the same if functions are called at very similar times - by El Forum - 09-13-2012, 02:20 AM



Theme © iAndrew 2016 - Forum software by © MyBB