views:

390

answers:

2

I'm trying to make a bookmarklet that will take the url of the current page you are on and send it to an application written in PHP with CodeIgniter.

The problem I keep running into, however, is that I can do a standard AJAX call because it's cross-domain so it's disallowed and I can't figure out a way to use the JSONP via GET method, since CodeIgniter blows away the $_GET variable.

At this point I'll take any suggestions on how to do this...I just want it to work. Also, please note that I need to send a url...and if it's to be passed via a url itself it obviously needs to be encoded or something...which I also haven't figured out how to do, so any pointers on that end (if needed) would be appreciated.

A: 

It is possible to enable query strings in Codeigniter, but watch out for the caveats - you can't use the URL helper, for example.

John McCollum
Good call...though it looks like it would require me to do query strings for the WHOLE site...which I would like to avoid...
Adam Haile
A: 

Codeigniter unsets $_GET but you can get the data from the query string. It is a little inefficient because PHP will probably end parsing the query string twice, but it should work:

parse_str($_SERVER['QUERY_STRING'], $get);
print_r($get);

All the GET variables should be accesible in the variable $get. See parse_str() documentation for some more information.


As an alternative you could url-encode the current URL and append it to what you are requesting e.g.

var url = 'http://example.com/bookmarklet/' 
               +  encodeURIComponent(window.location);

Then in Codeigniter do something like:

//you might have to call urldecode() on this value 
$url = $this->uri->segment(0);

but you may find you then have this problem

Tom Haigh
Ummm...could you clarify a little there...I have NO CLUE what that is.
Adam Haile