![]() |
need advice for creating personalized urls
i'm trying to figure out whats the best way I can do this..
i want to create a unique string either based on userid or email for personalized urls sort of like how youtube is: Code:
http://youtube.com/watch?v=eBGIQ7ZuuiU |
You just pull the row out with that value from the database. So that youtube video has an ID (or other identifying entity) of eBGIQ7ZuuiU
|
You can always md5() or sha1() the string combined with the time of creation.
Here is a SHA1 solution - it generates a 8 char string. strtoupper is there if you want to have uppercase letters instead lowercase. PHP Code:
if you url is Code:
http://yoursite.com/watch/C21D36C7/So in your database table should look like this |id | ident |....other | fields Hope this helpes |
I've just wrote us a nice function which generates identifiers just like YouTube :-) ! Not just limited to the hexadecimal range of 0 to F.
php Code:
You can even specify which types to include using the 3 arguments after the identifier length. All of which are set to true by default. You'll of course want to add your own checker to see if the returned identifier is unique. I recommend sticking in a do while loop for that -- outside of the function itself. |
Quote:
(im just using dupecheckid() function as an example - but the function would run a query like SELECT * FROM table WHERE uid = $id) $id = getIdentifier(6); if(dupecheckid($id)){ //identical id found in database $id = getIdentifier(6); }else{ //continue doing what it is doing } |
php Code:
|
| All times are GMT. The time now is 12:50 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0