-1

I am new to PHP. I need to GET a xml stored locally using PHP through a GET request

I tried this

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    echo "POST Request";
} else if ($_SERVER['REQUEST_METHOD'] == 'GET') {
    echo "GET Request";
}

So now i know what do in a POST/GET is encountered.

What to do next to get a XML?

hakre
  • 193,403
  • 52
  • 435
  • 836
coderslay
  • 13,960
  • 31
  • 73
  • 121
  • It largely depends on what you want to do with it. If you want to use it with an XML parser then the XML parser will probably have somewhere to enter the path. If you want to do something else with it, then it depends what that something else is. – Quentin Jun 12 '12 at 06:47
  • There are several request types other than GET and POST, you should not assume that a request that isn't POST is automatically GET. – Quentin Jun 12 '12 at 06:47
  • @Quentin Thanks for pointing out my this error that there are other request type also... Secondly i just need to send the entire xml back to the client..I don't have to parse it. The client will parse it at his end... How to return the entire xml back to client? – coderslay Jun 12 '12 at 06:50
  • Your question is not really clear. What do you mean by "get a XML"? – hakre Jun 12 '12 at 08:34
  • @hakre I meant get a XML response from the server. – coderslay Jun 12 '12 at 08:41
  • Which server? And what is a *XML repsonse*? You are saying words, but you don't say much. This needs much more context so that others can understand that. If it's simple, make it simple please, not too simple. – hakre Jun 12 '12 at 08:43
  • @hakre I need to write a php script at the server end which first detects whether it is a POST or a GET and then depending upon the request give back a XML response back to the Client. Is this clear enough? – coderslay Jun 12 '12 at 08:47
  • @Coder_sLaY: You can just return XML as you normally return HTML. Just output it and you're fine. Clear enough? See as well: [How can I echo HTML in PHP?](http://stackoverflow.com/questions/1100354/how-can-i-echo-html-in-php) – hakre Jun 12 '12 at 08:55
  • @hakre very clear. Thanks bro :) – coderslay Jun 12 '12 at 09:00

1 Answers1

2

Use the header function to output the correct content type for the XML you are using, then readfile.

Or just use header to output a Location header and let your webserver handle serving up the XML.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335