Passing full web address (slashes and all) as one segment - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Passing full web address (slashes and all) as one segment (/showthread.php?tid=33711) |
Passing full web address (slashes and all) as one segment - El Forum - 09-06-2010 [eluser]taurine[/eluser] I'm making a URL shortening script. I have it working with a normal form, but now I want to make a "services" version, where a 3rd party client like Tweetdeck could convert a URL. I can't necessarily control whether or not that client encodes the URL. This is my route: $route['tw/(:any)'] = "home/tw/$1"; Ideally, it would work like: http://example.com/tw/http://reallylongurl.com/blah/xyz.html Everything after http://example.com/tw/ would be converted into one variable. I want CI to stop working the slashes when it hits the $1. I tried things like $1- to no avail. Tried throwing urlencode() but couldn't get that working either. All I'm able to get in my method is the http: part. Any idea how I can get the full URL? Maybe something with .htaccess? Or maybe create a new (:url) type, like (:num) and (:any), if such a thing is possible? Passing full web address (slashes and all) as one segment - El Forum - 09-06-2010 [eluser]Clooner[/eluser] Pass the url as $_GET Passing full web address (slashes and all) as one segment - El Forum - 09-07-2010 [eluser]taurine[/eluser] How do I do that? I found a few other threads where people trying something similar (passing data with slashes in it) tried setting uri_protocol and enable_query_strings in the config, but none of them were resolved. In my own attempt at that method, everything else broke. The routes stopped working, and my url redirections (example.com/lskfj) stopped working too. Everything just routed to the default controller regardless of route setting. Or are you referring to something else? Is there a way to do that on a per controller basis, or interrupt CI before it chops up my data with slashes into segments? Thanks for guidance Passing full web address (slashes and all) as one segment - El Forum - 09-07-2010 [eluser]Clooner[/eluser] [quote author="taurine" date="1283858202"]How do I do that? I found a few other threads where people trying something similar (passing data with slashes in it) tried setting uri_protocol and enable_query_strings in the config, but none of them were resolved. In my own attempt at that method, everything else broke. The routes stopped working, and my url redirections (example.com/lskfj) stopped working too. Everything just routed to the default controller regardless of route setting. Or are you referring to something else? Is there a way to do that on a per controller basis, or interrupt CI before it chops up my data with slashes into segments? Thanks for guidance [/quote] Simply make sure the config is set to default so URI segments work. then simple rebuild the get parameters using Code: // rebuild and clean the $_GET Passing full web address (slashes and all) as one segment - El Forum - 09-07-2010 [eluser]taurine[/eluser] Thanks, that helped get me on the right track. I had to change things, because one of the slashes in http:// kept getting stripped, and the . kept getting turned into a _. //grab the request $data->x = $_SERVER['REQUEST_URI']; //strip off method "/tw/" from the front $data->x = str_replace("/tw/",'',$data->x); I put that in my controller's tw() method, and test echoing $x in my view, and it works! I couldn't find any reference to _clean_input_data on this website, and am not sure if I need it. Also, I'm not sure if accessing REQUEST_URI like I did is considered bad practice or anything, but it seems to be working, and was the only element variable that didn't mangle the data (// and .). Thanks for your help! Passing full web address (slashes and all) as one segment - El Forum - 09-07-2010 [eluser]CroNiX[/eluser] You could also convert the slashes to something that would be acceptable in the url and then change it back once you've grabbed it. |