I'm trying to achieve a unique ID, like tinyurl, but currently having trouble. I have a code up and it works almost, it adds a new letter if needed, but it only changes the first letter and I want it to change everything. I have already tried by checking the next letter at first in the loop but failed, so I hope someone here can help me out. CODE REMOVED, I SOLVED IT
I used to have a site like that but I sold it. Just make it randomly generate a like 6-7 digit code or something and then check to make sure it doesn't already exist. That other way is too complicated.
But achievable, I don't want any random strings and also will get hard to get a random one after a big database. And yea it's hard, that's why I posted it here, as I couldn't get any further then this. Currently: 63+63+63 possibilities in place of 63*63*63
If you don't mind the length just use an MD5 hash of userip + filename. You could even take the first 8 characters of the hash if you want. You don't necessarily need something as complicated as what you have there. Just make sure you have a way of checking to make sure you don't have any collisions. You could even do md5(time.userip.filename) and just use the first 8 chars. It's up to you! Using just the first 8 chars you will get about 4 trillion possible outputs.
I would recommend you just make a random string and then use a script to assign it to that URL. Your choice though.
I think I would take a different approach to this. If you can remove the numbers you can just increment the string. $q = mysql_query("SELECT `url_key` FROM `url` ORDER BY `id` DESC LIMIT 1"); if(mysql_num_rows($q) > 0) { $last_array = mysql_fetch_array($q); $last_url = $last_array['url_key']; $new_url = $last_url++; } else { $new_url = 'a'; } PHP: You wouldn't be able to use numbers but it should be a much simpler method of handling this.
It's a great approach, but I already tried that and this doesn't work correctly with more then one character It gets close, but it wont change the first letter, zzz becomes aaaa while azz is never been used or am I wrong?. EDIT: YES, I think I got it. I've noted all the possibilities I've got with the code: aaa - 9aa aba - a9a b9a - 99a aab - aa9 ba9 - 9a9 ab9 - a99 b99 - 999 Is this everything? EDIT2: False result, I tried it again and it does everything, yay! XD I own