Knowledgebase

PHP Encoding / Cipher / Unique String

Posted by ACTCS, 01-15-2013, 08:54 PM
This is for PHP 5 Long story short, we're working on an application which requires each item be assigned a unique alpha-numeric string. The character space for this is essentially base 62 (a-z, A-Z, 2-9: excluding I,1,l,0, and O). The goal is to create a unique string based on an auto-incrementing unique id field in sql. So far, so good... except: the string generated should "appear" to be random in nature. Our current iteration does everything required above but does not appear random. I'm posting hoping I've missed the obvious to make the resultant output LOOK random, but be easily decoded given the base62 alphabet. Thanks in advance. Encode/Decode Functions To create an encoded item: To decode;

Posted by TwineDev, 01-16-2013, 12:06 AM
Do you have a specific goal in mind other than that when someone looks at the code they don't see something like id=33 and then try to change it to id=34? If that is all that is needed, check out this thread where I posted two functions I used, then followed by discussion on some other methods http://forums.devnetwork.net/viewtopic.php?t=132062 -Greg

Posted by ACTCS, 01-16-2013, 10:23 AM
This is a good solution. I wasn't super clear in my original post, however. The object was to create an algorithm that was easily encoded/decoded without an sql query not unlike a url shortener (although this is a different implementation.) We wound up taking the original, rather predictable, base 56 encoded url and incrementing each digit by the offset of the last digit in the list. I've posted an example of the function below. I'd be happy to answer any questions if it's not clear.

Posted by TwineDev, 01-16-2013, 12:19 PM
Kinda busy right now, but now I think I know what you were getting at now. I'll try to remember where I put the code (finishing up a large project, there is code all over the place here... LOL) and post the method I used. -Greg



Was this answer helpful?

Add to Favourites Add to Favourites

Print this Article Print this Article

Also Read
no space left.. (Views: 535)
Jumpline Down Again (Views: 643)
tune httpd ? (Views: 594)


Language:

Client Login

Email

Password

Remember Me

Search