1

OK, firstly, I must be missing something, so I apologise for what may turn out to be a newb question...

I have a complicated bit of code that is just not working, so am putting it out here or any pointers. I can't share too much as it is proprietary, so here goes.

I have three tiers: User, server, appliance. The server, and appliance are php enabled, the client is either IE, or Chrome - the behavior is the same.

The user tier sends data from an HTML 5 form to the server, which in turn logs it in a database, and can send to the appliance - all OK here.

Due to the appliance not being https enabled I am trying to set up a trigger/response model. This means sending an abbreviated message, or key (as a GUID), to the appliance, and then the appliance calling back to the server for an XML message for processing. The call back is done using a get_file_contents() call.

All the parts seem to be working, the server response is retrieving the XML and the client is picking the XML headers correctly - however when the appliance is performing the call, the response is empty.

$result = file_get_contents($DestURL) ;
// If I call the value in $DestURL in a browser address 
// box - it all works
// If I echo the $result, it is empty, and then nothing 
// executes, except the last line.
if (strlen($result)== 0 ) {
    // ==> this is not executing <==
    $msg = "Failed to open the <a href='" . htmlspecialchars($DestURL) . "'> URL<a>: " . htmlspecialchars($DestURL);
    $result="Error";
}
// ==> this is not executing <<==
if ($result=="Error") 
    {
    /*
     * need to send an error message
     */
    }
else 
    {
    $result = PrintMessage($my_address, $result 
    }
// ==> This is executing <==
Echo "all Finished";
?>

Any ideas from anyone greatly appreciated.

The Server Web service reads like this:

<?php
   header("Content-type: text/xml");
   // a bunch of items getting the data from the database
   $result = mysqli_query($con, $sql);
   $row = mysqli_fetch_array($result);
   echo $row['message_XML'];
?>
btg_1967
  • 79
  • 1
  • 13
  • I think you have not configured the `file_get_contents` setting in php.ini file. make sure that is configured or not. – Code Lღver Aug 05 '13 at 14:10
  • Does `$DestURL` have https? – Salman Aug 05 '13 at 16:54
  • Thanks for the thought @Salman, sadly no - this is the reason I have to do the Trigger/response method as the response result will trigger a billable action, so I'm essentially doing a manual version of a rolling key to ensure try and make spoofing a whole load harder... – btg_1967 Aug 06 '13 at 12:17
  • @BrokenHeartღ you helped a massive amount... and put me on the right path. I've have to use details from another post to use CURL and it all works properly. – btg_1967 Aug 06 '13 at 12:19
  • @btg_1967 on the many server `file_get_contents` is not configured due to security reason. and this is good that you have used to curl. well cheers. +1 for your hard work. – Code Lღver Aug 06 '13 at 12:28

1 Answers1

0

I still have no real reason why this is happening, however a related post helped over here: PHP ini file_get_contents external url helped a huge amount - Thanks to both responses.

I've changed the get from using file_get_contents() to a CURL call. Problem Solved.

Here is the code:

function get_message($URL)
{
  /*
   * This code has been lifted from stackoverflow: URL to the article
  */
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_URL, $URL);
  // Can also link in security bits here.
  $data = curl_exec($ch);
  curl_close($ch);
  return $data;
}
Community
  • 1
  • 1
btg_1967
  • 79
  • 1
  • 13