Random URL Path Generator | PHP
Thursday, April 28, 2011 |
Edit Post
Creating randomized valid file paths is a common requirement for many applications such as the case of short url redirects. The Goo.gl url shortening service produces a random Alphanumeric file path 5 characters long. This allows letters A~z and decimal numbers 0~9. Five alphanumeric character ought to be enough in practice for most applications as this equates to 62^5 = 1 Billion (916,132,832) unique url combinations before you need to revisit the situation or run into a y2k wall of sorts.
For example, a short url may look something like this:
http://goo.gl/XMoug
Behind the scenes, this url is then redirected by the service to its proper destination such as http://wayne-doucette.blogspot.com/
Here's a function in PHP that returns an ASCII character array, defaulting to 5 characters in length. -Although the forward slash is a permissible character, I have not allowed it in my application as I do not wish the generated paths to represent file directories.
getHash() first loads a decimal array representing ASCII codes of the permissible character set, seeds the PHP random number generator, then finally builds and returns a random array of ASCII characters.
To implement the method, simply do something like this:
For example, a short url may look something like this:
http://goo.gl/XMoug
Behind the scenes, this url is then redirected by the service to its proper destination such as http://wayne-doucette.blogspot.com/
Here's a function in PHP that returns an ASCII character array, defaulting to 5 characters in length. -Although the forward slash is a permissible character, I have not allowed it in my application as I do not wish the generated paths to represent file directories.
getHash() first loads a decimal array representing ASCII codes of the permissible character set, seeds the PHP random number generator, then finally builds and returns a random array of ASCII characters.
To implement the method, simply do something like this:
Dynamic Page QR Code
Popular Posts
-
Product Manager Cover Letter: This real cover letter worked successfully at getting an interview as a product manager. Use it as a templat...
-
Creating randomized valid file paths is a common requirement for many applications such as the case of short url redirects. The Goo.gl url s...
-
If you're interested in placing QR tags dynamically on your site, here's how I did it in less than 5 minutes thanks to Google's ...
-
Cover Letter Examples that I have used successfully to get a job interview: Further to my last post on this topic, there's no substi...
-
Is there a scientific reason that can explain Why People are So stupid? It's not surprising that so many people take advantage of being...
-
Sample for Cover Letters Writing an effective cover letter is essential to get yourself noticed. Use your cover letter as a sample of your...
-
Decoded HTML Encoded HTML Entities /** * Encode HTML tags as HTML Entities * using jQuery * * Code takes raw...
-
In my opinion, Git is a programmers program. It is fast, feature-rich yet intuitive, kind of like Google...there's a new treasure waitin...
-
Blogger RSS URL s can be customized to syndicate content in a user friendly way. This is especially important if you operate a multi-issue b...
-
The example below uses Google's OpenID API to request and validate the user's GMail address. The visitor is first directed to Google...
0 comments:
Post a Comment