English 中文(简体)
CURL in php - I have 2 function that work seperatly, but whengam the second one products the results from the 1st cURL calls
原标题:cURL in php - I have 2 functions that work seperatly but when combined the second one outputs the results from the 1st cURL call
  • 时间:2011-10-02 20:24:32
  •  标签:
  • php
  • curl

我正设法建立快春订阅付款处理系统。

我有以下档案,载有2项职能。 第一组通过URL打电话,获取基本秩序信息。 在订购参考中,第二批客户按订单功能返回,并收到一些订阅信息。

这些职能在单独运作时是正确的。 但是,在共同运行时,第二个功能是东北大西洋渔业组织的工作,它正在产生第一件大呼吁的结果?

<?php

//order reference..
$OrderReference =  QUI110930-3371-94207B ;

//UNCOMMENT THIS IF JUST WANT TO TEST getSubscriber function on its own..
//$SubscriptionReference1 =  QUI110926-3371-68125S ;

getOrder ( $OrderReference );

getSubscription ( $SubscriptionReference1 );

//test our variaables for getOrder..
echo  <br/>1:  . $OrderReferrer;
echo  <br/>2:  . $beginDate;
echo  <br/>3:  . $display;
echo  <br/>4:  . $value;
echo  <br/>5:  . $productDisplay;
echo  <br/>7:  . $SubscriptionReference;
echo  <br/><br/><br/> ;

//test our variaables for getSubscriber
echo  <br/>1:  . $nextPeriodDate;
echo  <br/>2:  . $subscriptionUrlDetail;
echo  <br/><br/><br/> ;
print_r ( $test );

function getOrder($OrderReference) {

    $username =  my_username ;
    $pass =  my_password ;

    //Initialize handle and set options


    $payload =  -i -X GET -u   . $username .  :  . $pass;
    $requrl =  https://api.fastspring.com/company/quizba/order/  . $OrderReference;

    define (  XML_PAYLOAD , $payload );
    define (  XML_POST_URL , $requrl );

    $ch = curl_init ();
    curl_setopt ( $ch, CURLOPT_URL, XML_POST_URL );
    curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
    curl_setopt ( $ch, CURLOPT_TIMEOUT, 10 );
    curl_setopt ( $ch, CURLOPT_USERPWD, $username .  :  . $pass );
    curl_setopt ( $ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC );
    curl_setopt ( $ch, CURLOPT_HTTPHEADER, array ( Content-type: Application/xml  ) );
    curl_setopt ( $ch, CURLOPT_SSL_VERIFYHOST, 0 );
    curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, 0 );

    //Execute the request and also time the transaction


    $result = curl_exec ( $ch );
    if ($result ==   ) {
        $result = curl_exec ( $ch );
    }

    //Check for errors


    if (curl_errno ( $ch )) {
        $resultMsg =  ERROR ->   . curl_errno ( $ch ) .  :   . curl_error ( $ch );
    } else {
        $returnCode = ( int ) curl_getinfo ( $ch, CURLINFO_HTTP_CODE );
        switch ($returnCode) {
            case 404 :
                $resultMsg =  ERROR -> 404 Not Found ;
                break;
            case 200 :
                break;
            default :
                $resultMsg =  HTTP ERROR ->   . $returnCode;
                break;
        }
    }

    //Assign the variables..

    $resultArray = simplexml_load_string ( $result );
    global $OrderReferrer;
    $OrderReferrer = $resultArray->referrer [0];
    global $beginDate;
    $beginDate = $resultArray->statusChanged [0]; //needs to be modified..             
    global $display;
    $display = $resultArray->status [0];
    global $productDisplay;
    $productDisplay = $resultArray->orderItems->orderItem [0]->productDisplay [0];
    global $value;
    $value = $resultArray->total [0];
    global $SubscriptionReference;
    $SubscriptionReference = $resultArray->orderItems->orderItem [0]->subscriptionReference [0];

    //Close the handle


    curl_close ( $ch );
}

//get the subscription details

function getSubscription($SubscriptionReference) {
    $username =  my_username ;
    $pass =  my_password ;

    $payload =  -i -X GET -u   . $username .  :  . $pass;
    $requrl =  https://api.fastspring.com/company/quizba/subscription/  . $SubscriptionReference;

    define (  XML_PAYLOAD , $payload );
    define (  XML_POST_URL , $requrl );

    $newCh = curl_init ();
    curl_setopt ( $newCh, CURLOPT_URL, XML_POST_URL );
    curl_setopt ( $newCh, CURLOPT_RETURNTRANSFER, 1 );
    curl_setopt ( $newCh, CURLOPT_TIMEOUT, 10 );
    curl_setopt ( $newCh, CURLOPT_USERPWD, $username .  :  . $pass );
    curl_setopt ( $newCh, CURLOPT_HTTPAUTH, CURLAUTH_BASIC );
    curl_setopt ( $newCh, CURLOPT_HTTPHEADER, array ( Content-type: Application/xml  ) );
    curl_setopt ( $newCh, CURLOPT_SSL_VERIFYHOST, 0 );
    curl_setopt ( $newCh, CURLOPT_SSL_VERIFYPEER, 0 );

    //Execute the request and also time the transaction


    $newResult = curl_exec ( $newCh );
    if ($newResult ==   ) {
        $newResult = curl_exec ( $newCh );
    }

    //Check for errors


    if (curl_errno ( $newCh )) {
        $newResultMsg =  ERROR ->   . curl_errno ( $newCh ) .  :   . curl_error ( $newCh );
    } else {
        $returnCode = ( int ) curl_getinfo ( $newCh, CURLINFO_HTTP_CODE );

        switch ($returnCode) {
            case 404 :
                $newResultMsg =  ERROR -> 404 Not Found ;
                break;
            case 200 :
                break;
            default :
                $newResultMsg =  HTTP ERROR ->   . $returnCode;
                break;
        }
    }

    //Assign the variables..


    global $test;
    $test = $newResult;
    //$newResultArray = new SimpleXMLElement($newResult, NULL, FALSE);
    $newResultArray = simplexml_load_string ( $newResult );

    global $nextPeriodDate;
    $nextPeriodDate = $newResultArray->nextPeriodDate [0]; //needs to be modified..                 
    global $subscriptionUrlDetail;
    $subscriptionUrlDetail = $newResultArray->customerUrl [0];

    //Close the handle


    curl_close ( $newCh );
}
最佳回答

由于您使用<代码>define (XML_POST_URL ,$requrl ); 您无法使用该软件提出2项申请。

你们不能用定义来掩盖,永远保持第一价值。 除非你在使用该文字的某个地方(并且无法用固定变量转让这些变量),否则你不应使用定义。

define() is a good function for using in (for example) a config file, where you set a URL you need to use on a lot of other places. These variables should be constants, and should not be changing.

注:你不应使用全球数据,而是在阵列或变数中恢复这一功能的价值。

问题回答

暂无回答




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签