Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

PHP - Similar CURL request in two script returns different responses

I have got Similar CURL request in two script that returns different responses.

One returns 200 with the exact response data I expect while the other returns 500 error.

Code in Script 1 (which returns 200 - successful response):

    <?php 


if ($_POST){    

$m = $_POST['m']; 
$s = $_POST['s']; 
$tr = $_POST['tr']; 
$a = $_POST['a']; 
$c = $_POST['c'];
$tt = $_POST['tt']; 

$url = "http://197.210.183.238/UnityPayServices/ws/dosigntransaction";       

        $content = json_encode(array( 
            'merchantid' => $m,
            'storeid'       => $s,   
            'trxnreference' => $tr,
            'amount'    => $a,
            'currencycode' => $c,
            'transactionType'      => $tt
            ));                                             


        $curl = curl_init($url);
        curl_setopt($curl, CURLOPT_HTTPHEADER,   array("Content-type: application/json"));
        curl_setopt($curl, CURLOPT_HEADER, false);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_POST, true);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $content);
        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
        $json_response = curl_exec($curl); 
        $http = curl_getinfo($curl, CURLINFO_HTTP_CODE);

        curl_close($curl); 

        //var_dump($json_response);

        $response_array = json_decode($json_response, true);

        var_dump($http);

        echo '<br>';
        echo '<br>';

        var_dump($response_array);

}

?>


<form action="" method="post">
    <input type="hidden" name="m" value="UB141118101622" />
    <input type="hidden" name="s" value="200208" />
    <input type="hidden" name="tr" value="5950" />
    <input type="hidden" name="a" value="50000" />
    <input type="hidden" name="c" value="NGN" />
    <input type="hidden" name="tt" value="Info Bit" />

    <input type="submit" class="awesome_btn" name="submit_form" value="Get data" />

</form>

Code in Script 2 (which returns 500 or other error status - NO response data):

<?php 


$m = 'UB141118101622'; 
$s = '200208'; 
$tr = 5950; 
$a = 50000; 
$c = 'NGN';
$tt = 'Info Bit'; 


$url = "http://197.210.183.238/UnityPayServices/ws/dosigntransaction";       

        $content = json_encode(array( 
            'merchantid' => $m,
            'storeid'       => $s,   
            'trxnreference' => $tr,
            'amount'    => $a,
            'currencycode' => $c,
            'transactionType'      => $tt
            ));                                             


        $curl = curl_init($url);
        curl_setopt($curl, CURLOPT_HTTPHEADER,   array("Content-type: application/json"));
        curl_setopt($curl, CURLOPT_HEADER, false);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_POST, true);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $content);
        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
        $json_response = curl_exec($curl); 
        $http = curl_getinfo($curl, CURLINFO_HTTP_CODE);

        curl_close($curl); 

        //var_dump($json_response);

        $response_array = json_decode($json_response, true);


        var_dump($http);

        echo '<br>';
        echo '<br>';

        var_dump($response_array);


?>

As shown above, if both scripts are saved in two sample files test1.php and test2.php, the only difference in both script is that one is sent while processing a POST submit request while the other request is initiated if the script hits the browser directly.

Being racking my head as to why the other keeps returning a 500 internal server error because I really need it to work in the other where the request hits the CURl request hits the browser directly.

Help will be greatly appreciated!

Thanks!

Comments