开发者

How can you pass GET values to another url in php? GET value forwarding

开发者 https://www.devze.com 2022-12-28 12:04 出处:网络
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 loca

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.


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, '', '&'));


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().


Got it! Thanks Alix Axel!

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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消