Security settings blocking the use of the stream and file functions.

You are here

2 posts / 0 new
Last post
thomash
Security settings blocking the use of the stream and file functions.

Integrator discovered that our sample code worked fine against his test server. However, when he moved his code to production he received security warnings blocking the use of stream and file functions within the sample code. This specifically refers to our use of file_get_contents within PHP in the makePostRequest function.

 

Example:

    function makePostRequest($body, $url){

        $config = [
            "http" => [
                "header" => [
                    "content-type: application/x-www-form-urlencoded",
                    "accept: application/xml"
                ],
                "method" => "POST",
                "content" => $body
            ]
        ];

        $context = stream_context_create($config);
        $result = file_get_contents($url, false, $context);

        return $result;
    }
thomash
Re: Security settings blocking the use of the stream and file fu

Using file_get_contents includes cURL. In order to overcome the issue with the security settings the integrator used the cURL function directly. I have included an example below. If you have any questions or need additional help, please feel free to contact our team at [email protected].

 

Example:

    function makePostRequest($body, $url){

        $ch = curl_init($url);

        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'content-type: application/x-www-form-urlencoded',
            'accept: application/xml'
        ));

        $result = curl_exec($ch);
        curl_close($ch);
        
        return $result;
    }
Log in or register to post comments