I would like to send a xml response when a url is hit with parameters like http://gmail.com/cb/send/send.php?user_name=admin1&password=test123&subscriber_no=1830070547&mask=Peter&sms='Test SMS'
When one will hit this link then a response will be given which will like
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 am calling this method from my controller file and just echo the value. will the hitter will get this response?
<?php
......
......
echo $sendResponse($type,$cause);
?>
Will user will get resonse by this echo?
return
alone won't sending anything to the client. If you are echoing the result of sendResponse()
then yes, the client will receive the XML:
echo sendResponse($type,$cause);
Notice I removed the $
from the sendResponse call - PHP will assume it's a variable if you use the $
.
It's recommended to add a header to tell the client that XML is being sent and the encoding, but it's not essential for the transport of the XML:
header("Content-type: text/xml; charset=utf-8");
You can use the concatenation character .
after you declared 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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With