URL shortening service |
[eluser]Dregond Rahl[/eluser]
Code: http://moourl.com/ How is shortening done? does it make a file? or is it thru the database? If it is thru a database would caching be useful in this situation? I'm trying to integrate it with my file uploader so im trying to get it so Code: http://uqyg.com/NhDgy.png works and if its a shortening url Code: http://uqyg.com/YAtHD and if it doesn't exists it will redirect to either 404 or homepage Thanks for all your opinions and suggestions
[eluser]xwero[/eluser]
Url shortening websites probably will use a database but if the site is small you could get away storing the shortened urls in a file with a php array and include that so all you have to do to is an isset check to find out if the image is available or not. I think to keep the files as small as possible i would create one for each shortened begin letter so the lookup method could be Code: function pic($url)
[eluser]Yorick Peterse[/eluser]
It does it using Curl I believe. You can use my plugin which uses third party services : http://codeigniter.com/wiki/Shortify_Plugin/
[eluser]xwero[/eluser]
[quote author="Yorick Peterse" date="1243951350"]It does it using Curl I believe. [/quote] Why should the url shortener service act as a proxy? If it's an outside url the best thing to do is just forward to the url using a 301 error message. If the service stops search engines will have the correct url instead of the shortened url. If the service acts as a proxy the server setup is more costly than with the forwarding solution.
[eluser]Dregond Rahl[/eluser]
[quote author="xwero" date="1243951302"]Url shortening websites probably will use a database but if the site is small you could get away storing the shortened urls in a file with a php array and include that so all you have to do to is an isset check to find out if the image is available or not. I think to keep the files as small as possible i would create one for each shortened begin letter so the lookup method could be Code: function pic($url) Thanks for giving me some options. I think i will use a database system, would be better in the long run for storing other details in case, and modifying. If im using the DB method, i would need to keep looking up from the database and then redirecting right? using CI can i cache only those requests to that specific table ?
[eluser]jdfwarrior[/eluser]
Yeah using the database as storage would probably be the better way to start. And as far as caching, the caching built into CI is a per query cache. "CodeIgniter places the result of EACH query into its own cache file." Code: // Turn caching on So you can't cache them all unless you force it to (chron job to query for a list of all shortened URLs, then, foreach, query it with caching enabled). Otherwise, the first time the shortened URL is requested it will perform the db lookup, and from there on out it would be cached (if that's how you set it up).
[eluser]Dregond Rahl[/eluser]
Thanks jdfwarrior for clearing that up for me. okie iv come into another problem, probably will involve routing or .htaccess I need to make urls that are like Code: http://uqyg.com/MwqJE route to Code: http://uqyg.com/snip/MwqJE and still allow links like Code: http://uqyg.com/snip Would i need to list out each and every route that is a controller or is there an easy way of figuring out that is part of the system and what isn't.
[eluser]TheFuzzy0ne[/eluser]
My take on a similar service: Code: function shorten_url($url) (Sorry, couldn't resist). ![]()
[eluser]jdfwarrior[/eluser]
You would definitely use routes and then at the bottom of your routes list would create a route for :any, which would be a route to /snip/$1. For that controller, you would use the _remap function. Take that first parameter, query the database for it and see if it existed as a shortened url, if it did, grab the full url from the database and then call a redirect to it. If not, show_404() Fuzzy's way also makes short urls ![]()
[eluser]xwero[/eluser]
It depends how many more controllers you have. If it's a url shortener service the controllers will be limited so you can add them to the route config file Code: $route['([a-zA-Z0-9]+)'] = 'snip/url/$1'; If you have quite a few controllers you can add a tilde for example before the actual shortened part so you get http://uqyg.com/~MwqJE which you can route. Code: $route['~([a-zA-Z0-9]+)'] = 'snip/url/$1'; |
Welcome Guest, Not a member yet? Register Sign In |