views:

183

answers:

4

Ok, so I'm using Jquery's AJAX function and it's having trouble passing a URL with a http address. So I'm hoping to "get" the GET values and send them to another URL — so: a local php file begin passed GET values, which in turn forwards the GET values to another url.

Maybe curl is the answer? I don't know. It's got to be a very short answer I know.

pseudo code:

//retrieve the GET values
$var retrieve [GET]

//passing it to another url
send get values to url ($var, url_address)

edit: It's a cross scripting solution for JavaScript.

A: 

header("Location: http://otherurl.com/page?var=" . $var);

sblom
that doesn't seem to work very well. I'm gettting a 302 error in Firebug's console.
michael
Concatenation is done with the `.` operator in PHP.
alex
-1, this doesn't forward the GET values at all.
Alix Axel
A: 

If you want to exclude a GET param, just unset() before using http_build_query(). It might also be a good idea to include a whitelist of $_GET params that you'd like to pass around.

   header('Location: http://example.com/new?' . http_build_query($_GET));
   exit;

Docs. Don't forget to exit().

alex
are you sure JS object would understand such a response?
Col. Shrapnel
@Col. Shrapnel I didn't 100% understand the question, but hoped sblom was on the right track.
alex
+4  A: 

If you want to redirect the user:

header('Location: http://example.com/page.php?' . http_build_query($_GET, '', '&')); die();

If however you just want to fetch the page, use this:

file_get_contents('http://example.com/page.php?' . http_build_query($_GET, '', '&'));
Alix Axel
A: 

Got it! Thanks Alix Axel!

echo file_get_contents('http://example.com/page.php?'. http_build_query($_GET, '', '&'));
michael
alex
Turns out it's a cross domain scripting problem that occurs with javascript. Yahoo has an article about it, they use cURL-- a little bit more complicated. http://developer.yahoo.com/javascript/howto-proxy.htmlSo this line of code is a simple php proxy.
michael