URL as query segment |
[eluser]d910qf[/eluser]
Hi all, I've done some reading and searching but not found an adequate solution yet. I need to be able to pass a full URL (which could contain any of ? & / : etc) to a controller as myapp.com/controller/function/<encodedurlhere> I have tried to both urlencode and base64_encode the url before passing it but neither is working - urlencode get's decoded before the function gets called it seems and base64_encode seems to work but the function doesn't like it. I've read you can use CodeIgniters internal encrypt class to do it but this is for people outside of the site to request thumbnail images of the URL so that is not an option (it has to be a standard php function). Does anyone have any ideas? I can't even find out how you can pass a query paramater to a function like myapp.com/controller/function/?url=encodedurlhere (without using myapp.com?c=asdas&m=sdfsdf&url=asdfsadf which would be a last resort). Cheers, Chris.
[eluser]BnoL[/eluser]
I got an idea. You can check if it works for you Firstly, you have to define a route for your URL: for example: http://localhost/get_thumbnail/{url_here} so, if the request URL is: http://www.some-domain.com/index.php?ada...dasd=gvddf for example. the URL to your site must be: http://localhost/get_thumbnail/http://www.some-domain.com/index.php?ada...dasd=gvddf and now we'll get the request URL: Code: if($this->uri->segment(1) == "get_thumbnail") // if the 1st segment is "get_thumbnail" I've tested, and it works fine for me There are might be better solutions =]. Storm your brain!
[eluser]slowgary[/eluser]
But that code makes some assumptions, such as the existence of a question mark in the url. Couldn't you just enable query strings in CodeIgniter and then choose a delimiter to wrap the URL in? Something like: Code: http://myapp.com/controller/get_thumbnail/{http://www.somedomain.com/index.php?234aqwf=asdf&acvd=q23f} Code: http://myapp.com/controller/get_thumbnail/http://www.somedomain.com/index.php?234aqwf=asdf&acvd=q23f/get_thumbnail
[eluser]BnoL[/eluser]
How about this? Code: echo end(explode('/get_thumbnail/',$_SERVER['REDIRECT_URL']))."?".$_SERVER['QUERY_STRING'];
[eluser]d910qf[/eluser]
Hi - thanks for the replies. For the following: http://myapp.com/controller/get_thumbnai...&acvd=q23f} How do I access the content between { }? I have enabled query strings in the config but I am not clear how using the above example would work? Chris.
[eluser]d910qf[/eluser]
I should probably explain! The reason why the url (whether encoded or not) needs to be there is that the idea is that people can embed thumbnails in this way: <img src="http://myapp.com/thumbnail/urlgoeshere/" /> I may add extra parameters for height, width, format etc. I can't believe this is so tricky to accomplish - is there any way to disable CodeIgniters automatic urldecoding on a per controller or function basis?
[eluser]d910qf[/eluser]
Answer found at http://ellislab.com/forums/viewthread/120460/#601577 set $config['uri_protocol'] = "PATH_INFO"; and then in your controller parse_str(urldecode($this->input->server('QUERY_STRING')), $get_array); now you can have url like http://myapp.com/thumb/generate/?url=<en...format=jpg and all the values are available in the $get_array array. Simple! |
Welcome Guest, Not a member yet? Register Sign In |