Skip to content

Instantly share code, notes, and snippets.

@igoralves1
Last active May 5, 2017 15:37
Show Gist options
  • Save igoralves1/ec7d732db20f3d4415aee7c50275973b to your computer and use it in GitHub Desktop.
Save igoralves1/ec7d732db20f3d4415aee7c50275973b to your computer and use it in GitHub Desktop.
Getting a xml by POST, testing some condition in the Request Header
<?php
//Grab and test the header INFO
if (!function_exists('getallheaders'))
{
function getallheadersNGX()
{
$headers = '';
foreach ($_SERVER as $name => $value)
{
if (substr($name, 0, 5) == 'HTTP_')
{
$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
}
}
return $headers;
}
}
//Traverse the header INFO
foreach (getallheadersNGX() as $name => $value) {
$arrHeaderInfo[$name]= $value;
}
or
$sender=$_SERVER['HTTP_HOST'];
echo $sender;
if ($_SERVER['REQUEST_METHOD']=="POST" && $arrHeaderInfo["someTagCompany"]=="VISA" ){
//Grab the body
$dataPOST = trim(file_get_contents('php://input'));//Getting by POST
$xml=simplexml_load_string($dataPOST);
$json_string = json_encode($xml);
#echo $json_string;
$result_array = json_decode($json_string, TRUE);
$someVar = $result_array['someVar'];
#var_dump($result_array);//Will display the array
#echo "authNo=".$result_array['authNo'];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment