Welcome Guest, Not a member yet? Register   Sign In
Creating a uniqd id for users upload folder name
#3

(03-04-2017, 08:57 PM)PaulD Wrote: When I create a user table, I assign a 'code' string to the user so I can refer to them in urls, something like users/view_profile/jfghdskjih so I would use that string (which is unique for each user and never changing) as the folder name.

I still use a piece of code suggested by Narf quite a long time ago for generating 'almost' guaranteed unique codes. I find it very useful and use it in some way on almost every site I do. Here it is in Narfs original form:

Code:
$code = bin2hex(pack('N', microtime(TRUE))).bin2hex(get_instance()->security->get_random_bytes(4));
https://forum.codeigniter.com/thread-634...#pid324949

I have a functions library full or things I find really handy that I transfer to all my sites and one of the functions in there is generate_code() which is the above function.

Just thought that might be of some use.

FYI, get_instance()->security->get_random_bytes() binds you to the framework.

You can replace that with random_bytes() - native on PHP 7+ or via a compat package on older versions: https://github.com/paragonie/random_compat

When available, CI_Security::get_random_bytes() will just proxy to that function anyways.
Reply


Messages In This Thread
RE: Creating a uniqd id for users upload folder name - by Narf - 03-06-2017, 02:06 AM



Theme © iAndrew 2016 - Forum software by © MyBB