标头不重定向

时间:2011-12-13 21:57:23

标签: php curl

此文件应重定向到标题中指定的URl,但显示空白页。 如果您取消对某些结果的评论,它会显示预期值。

<?php
sendReceiveOrder($Amnt);

    function sendReceiveOrder($Amnt) {
        //$ch = curl_init ();


        $description = $_POST['gtpay_tranx_memo'];

        $receivedXML = "";
        $receivedXML .= "<?xml version='1.0' encoding='UTF-8'?>";
        $receivedXML .= "<TKKPG>";
        $receivedXML .= "<Request>";
        $receivedXML .= "</Request>";
        $receivedXML .= "</TKKPG>";

        // Define POST URL and also payload
        //
        define ( 'XML_POST_URL', 'http://127.0.0.1:5555/Exec' );


        // Initialize handle and set options


        $ch = curl_init ();
        curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
        curl_setopt($ch,CURLOPT_MAXREDIRS,50);
        if(substr($url,0,8)=='https://'){
        // The following ensures SSL always works. A little detail:
        // SSL does two things at once:
        //  1. it encrypts communication
        //  2. it ensures the target party is who it claims to be.
        // In short, if the following code is allowed, CURL won't check if the 
        // certificate is known and valid, however, it still encrypts communication.
        curl_setopt($ch,CURLOPT_HTTPAUTH,CURLAUTH_ANY);
        curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);

    }
        curl_setopt ( $ch, CURLOPT_URL, XML_POST_URL );
        curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
        curl_setopt ( $ch, CURLOPT_TIMEOUT, 500 );
        curl_setopt ( $ch, CURLOPT_POSTFIELDS, $receivedXML );
        curl_setopt ( $ch, CURLOPT_HTTPHEADER, array ('Connection: close' ) );


        //---Additional stuff

    curl_setopt($ch, CURLOPT_CAINFO, getcwd() . "/tdpayment/cert/ETECHNOL.pem");

    //----------

        /**
         * Execute the request and also time the transaction
         */
        $start = array_sum ( explode ( ' ', microtime () ) );
        $result = curl_exec ( $ch );
        $stop = array_sum ( explode ( ' ', microtime () ) );
        $totalTime = $stop - $start;

        /**
         * Check for errors
         */
        if (curl_errno ( $ch )) {
            $result = 'cURL ERROR -> ' . curl_errno ( $ch ) . ': ' . curl_error ( $ch );
        } else {
            $returnCode = ( int ) curl_getinfo ( $ch, CURLINFO_HTTP_CODE );
            switch ($returnCode) {
                case 200 :
                    break;
                default :
                    $result = 'HTTP ERROR -> ' . $returnCode;
                    break;
            }

        }

        /**
         * Close the handle
         */
        curl_close ( $ch );

        /**
         * Output the results and time
         */

        //echo 'Total time for request: ' . $totalTime . "\n";
        //echo $_SESSION ['Amt'];
        //echo $result ;

        //echo "<br>";

    $_SESSION['store_result'] = $result;



        //echo $Amnt;
        //echo $description;
        //return $result;

        /**
         * Exit the script
         */
         $result2 = <<<XML
    <?xml version='1.0' standalone='yes'?>
    $result
    XML;


    $TKKPG = new SimpleXMLElement($result2);
    $orderid =  $TKKPG->Response->{'Order'}->OrderID;
    $sessionid =  $TKKPG->Response->{'Order'}->SessionID;
    $url = $TKKPG->Response->{'Order'}->URL;


    $_SESSION['ordersessionid'] = $orderid.$sessionid;

    $header = $url."?sessionid=".$sessionid."&orderid=".$orderid;


    header ("Location: ".$header);   

        exit ( 0 );
    }
    ?>

0 个答案:

没有答案