Sending xml response when hit url in php

I would like to send an xml response when the URL hits with parameters like http://gmail.com/cb/send/send.php?user_name=admin1&password=test123&subscriber_no=1830070547&mask=Peter&sms= 'Test SMS'

When someone hits this link, an answer will appear that will please

public function sendResponse($type,$cause) { $response = '<?xml version="1.0" encoding="utf-8"?>'; $response = $response.'<response><status>'.$type.'</status>'; $response = $response.'<remarks>'.$cause.'</remarks></response>'; return $response; } 

I call this method from my controller file and just an echo value. Will the attacker get this answer?

 <?php ...... ...... echo $sendResponse($type,$cause); ?> 

Will the user receive a response from this echo?

+4
source share
2 answers

return by itself will not send anything to the client. If you echo the result of sendResponse() , then yes, the client will receive XML:

 echo sendResponse($type,$cause); 

Notice that I removed $ from the sendResponse call - PHP will consider it a variable if you use $ .

It is recommended that you add a header to tell the client that the XML is being sent, and the encoding, but this is not essential for the XML transport:

 header("Content-type: text/xml; charset=utf-8"); 

You can use the concatenation character . after declaring the XML header:

  public function sendResponse($type,$cause) { $response = '<?xml version="1.0" encoding="utf-8"?>'; $response .= '<response><status>'.$type.'</status>'; $response = $response.'<remarks>'.$cause.'</remarks></response>'; return $response; } .... .... header("Content-type: text/xml; charset=utf-8"); echo sendResponse($type,$cause); 
+9
source

You just need to specify some kind of heading in your script that tells the browser / client to correctly handle this content! Other than that you need to concatenate, not reassign your $ response var;)

In php this should do the job:

 header("Content-type: text/xml;charset=utf-8"); 
+3
source

Source: https://habr.com/ru/post/1447186/


All Articles