开发者

How to pass GET variables from php to php on another server

In a php script I am receiving some data:

$data = $_POST['someData'];

How can I do something like this:

goToThisUrl( "http://someDomain.com/someScript.php?data = ".$data );

or if it is easier how can I do it by POST?

BTW. This is not happening in a browser, the first php script is getting called by a cart when the order is 开发者_运维技巧paid for (if it makes any difference)


Replace goToThisUrl with the real function file_get_contents and remember to urlencode($data) and that would work just fine.

If you want to POST the data instead, look at cURL. Typing "[php] curl post" into the search box will get you the code.


If you want to send the user there, then:

header('Location: http://someDomain.com/someScript.php?data='.$data);
exit;

Or if you just want to call the other server, you can do:

$response = file_get_contents('http://someDomain.com/someScript.php?data='.$data);

Both assume data is already a urlencoded string, you might want to use 'data=' . urlencode($data) or just http_build_query($data) otherwise.


foreach ($_POST as $key => $val) {
  $qs = urlencode($key) . "=" . urlencode($val) . "&";
}
$base_url = "<url here>";
$url = $base_url . "?" . $qs;
header('Location: $url'); exit();
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜