0

I want to make an application that will be receiving get requests and respond with xml. Here's the scenario:

User comes to site_a.com?site.phpid=abc, from there I have to make a GET request to site_b.com/checker.php?id=abc.

How to make a GET request without user leaving the page?

Inside checker.php I have to respond with xml depending on that id

if(isset($_GET['id'])){
  if($_GET['id']=='abc'){
    // respond with xml
 }
}

and then is site.php I have to receive that xml.

Thanks!

4

2 回答 2

2

最简单的方法,您可以使用file_get_contents

//site.php?id=abc
$xmlResponse = file_get_contents("site_b.com/checker.php?id=abc");

但确保allow_url_fopen可以是真的。
http://php.net/manual/en/filesystem.configuration.php

于 2012-04-25T13:09:25.293 回答
2

You could use curl.

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, 'http://site_b.com/checker.php?id=' . $id); 
curl_setopt($ch, CURLOPT_HEADER, 1); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
$xml = curl_exec(); 
curl_close($ch);

curl docs

于 2012-04-25T13:11:53.110 回答