Welcome Guest, Not a member yet? Register   Sign In
Passing full web address (slashes and all) as one segment
#1

[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://reallylongu...h/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?
#2

[eluser]Clooner[/eluser]
Pass the url as $_GET
#3

[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 Smile
#4

[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 Smile[/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
parse_str($_SERVER['QUERY_STRING'], $_GET);
// now it uses the same cleaning as sanitize_globals!
$this->input->_clean_input_data($_GET);
#5

[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!
#6

[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.




Theme © iAndrew 2016 - Forum software by © MyBB