URL shortening service |
[eluser]xwero[/eluser]
[quote author="TheFuzzy0ne" date="1243964884"]My take on a similar service: Code: function shorten_url($url) (Sorry, couldn't resist). ![]() It doesn't work as you return h every time or if you are lucky someone will get f, g, m, t or s. If you want an url shortener service quick and dirty try Code: function shorten_url($url)
[eluser]Dregond Rahl[/eluser]
Thanks everyone ^^ even you Fuzzy :p I don't quite understand the __remap() method O.o and xwero your idea works i might add a ~ , what other symbols are allowed? Also this doesn't seem to be working =/ Code: $route['~([a-zA-Z0-9]+)'] = "snip/re_link/$1"; EDIT: Also if possible, how would i check if the input was a valid URL, And thanks xwero for that alternative method, I might have a use for it for another project.
[eluser]xwero[/eluser]
you need to add the tilde (~) to the allowed_characters as the segments are validated before the routing takes place.
[eluser]Dam1an[/eluser]
The tilde is part of allowed characters by default Code: $config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-'; Edit: And I'm not sure what could be causing it to not work :-S
[eluser]Dregond Rahl[/eluser]
Code: $config['permitted_uri_chars'] = 'a-z 0-9~%.:_-'; its already there by default =/ Code: $route['default_controller'] = "main"; That's what i have so far, Example url that works: Code: http://uqyg.com/~JaJh the routing doesn't work tho =/
[eluser]jdfwarrior[/eluser]
Well theres different ways of doing it. Certainly the way xwero is telling you is a valid way as well, I just mentioned the way with the _remap function because of the way you formed the other url. As an explanation of what I was talking about.. You would create your route: Code: $route['(:any)'] = snip/$1; Then in your controller you would create a _remap function. It's purpose is to override index as the default function. Instead remap would be called and accept the next uri segment (supposed to be the function) as a parameter. Code: function _remap($url) Obviously the url functions are made up, checking the database and such would be your own method, I was just showing an example. That would be in your snip controller and coupled with the route I mentioned, would allow you to access short urls via: http://domain.com/snip/<id> or with the route configured, http://domain.com/<id>
[eluser]xwero[/eluser]
which routing doesn't work? the routing to the other controllers?
[eluser]Dregond Rahl[/eluser]
http://uqyg.com/~JaJh the routing of the snip =] EDIT: OKie i figured out whats wrong the ~ before $1 Code: $route['~([a-zA-Z0-9]+)'] = "snip/re_link/~$1"; Sorry guys XD, thanks for all your help <33333 Also is this method good for validating URLs? or would you recommend a different method? http://www.w3schools.com/PHP/filter_validate_url.asp |
Welcome Guest, Not a member yet? Register Sign In |