I am working on setting up credit card processing for a site that is live. PHP wasn't compiled with CURL support and I don't want to take the site down to recompile PHP with that, so I am trying to use a different method than the example code provided.
Example CURL code:
function send($packet, $url) {
    $header = array("MIME-Version: 1.0","Content-type: application/x-www-form-urlencoded","Contenttransfer-encoding: text"); 
    $ch = curl_init();
    // set URL and other appropriate options 
    curl_setopt($ch, CURLOPT_URL, $url); 
    curl_setopt($ch, CURLOPT_VERBOSE, 1); 
    curl_setopt ($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); 
    // Uncomment for host with proxy server
    // curl_setopt ($ch, CURLOPT_PROXY, "http://proxyaddress:port"); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
    curl_setopt($ch, CURLOPT_POST, true); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $packet); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt ($ch, CURLOPT_TIMEOUT, 10); 
    // send packet and receive response
    $response = curl_exec($ch); 
    curl_close($ch); 
    return($response);
}
My attempt to use a different method:
function send($packet, $host, $path) {
    $content = '';
    $flag = false;
    $post_query = urlencode($packet) . "\r\n";
    $fp = fsockopen($host, '80');
    if ($fp) {
        fputs($fp, "POST $path HTTP/1.0\r\n");
        fputs($fp, "Host: $host\r\n");
        fputs($fp, "Content-length: ". strlen($post_query) ."\r\n\r\n");
        fputs($fp, $post_query);
        while (!feof($fp)) {
            $line = fgets($fp, 10240);
            if ($flag) {
                $content .= $line;
            } else {
                $headers .= $line;
                if (strlen(trim($line)) == 0) {
                    $flag = true;
                }
            }
        }
        fclose($fp);
    }
    return $content;
}
While this does actually give me a return from the URL I am calling, it does so incorrectly because I get an error back saying it was formatted incorrectly. I am not very familiar with either CURL or this other method, so I am not sure what I am doing wrong.