php curl语法检查

时间:2016-11-28 16:01:00

标签: php curl

<?php
error_reporting(E_ALL);
       $ch = curl_init();
    ini_set('max_execution_time', 0); ini_set('set_time_limit', 0);
    curl_setopt($ch, CURLOPT_URL, "https://security.voluum.com/login");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");


    $headers = array();
    $headers[] = "Authorization: Basic username:password"; 
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

    $result = curl_exec($ch);
    if (curl_errno($ch)) {
        echo 'Error:' . curl_error($ch);
    }
    $res_decoded = json_decode($result);
    $tok = $res_decoded->token;
    $id = 'asdafewfcs';
    $karon =  date("Y-m-d");
    $datetime = new DateTime('tomorrow');


     $sh = curl_init();
    curl_setopt($sh, CURLOPT_URL, "https://portal.voluum.com/report?from=" .$karon. "T00:00:00Z&to=" . $datetime->format('Y-m-d') . "T00:00:00Z&tz=Etc%2FGMT&sort=revenue&direction=desc&columns=offerName&columns=visits&columns=clicks&columns=conversions&columns=revenue&columns=cost&columns=profit&columns=cpv&columns=ctr&columns=cr&columns=cv&columns=roi&columns=epv&columns=epc&columns=ap&columns=affiliateNetworkName&groupBy=offer&offset=0&limit=100&include=active&filter1=campaign&filter1Value=" . $id);
    curl_setopt($sh, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($sh, CURLOPT_CUSTOMREQUEST, "GET");


    $header = array();
    $header[] = "Cwauth-Token: " . $tok; 
    curl_setopt($sh, CURLOPT_HTTPHEADER, $header);

    $results = curl_exec($sh);
    if (curl_errno($sh)) {
        echo 'Error:' . curl_error($sh);
    }

$user = json_decode($results, true);
echo '<pre>' . print_r($user, TRUE) . '</pre>';
foreach($user['rows'] as $mydata)
{
            $visit = $mydata['visits'] ;
            echo $visit . "\n<br>";
            if($visit >= 10){

                $wh = curl_init();

            curl_setopt($wh, CURLOPT_URL, "https://core.voluum.com/campaigns/" . $id);
            curl_setopt($wh, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($wh, CURLOPT_CUSTOMREQUEST, "GET");


            $head = array();
            $head[] = "Cwauth-Token: " . $tok;
            curl_setopt($wh, CURLOPT_HTTPHEADER, $head);

            $resulta = curl_exec($wh);
            if (curl_errno($wh)) {
                echo 'Error:' . curl_error($wh);
            }
            echo "Request:" . "<br>";
            $campinfo = json_decode($resulta, true);
            echo '<pre>' . print_r($campinfo, TRUE) . '</pre>';
            foreach($campinfo['pathsGroups'] as $datacamp){
                echo $datacamp['active'];
                $xh = curl_init();//starts not working when i add codes from here to end

                curl_setopt($xh, CURLOPT_URL, "https://core.voluum.com/campaigns/" . $id);
                curl_setopt($xh, CURLOPT_RETURNTRANSFER, 1);
                curl_setopt($xh, CURLOPT_POSTFIELDS,http_build_query(array($datacamp['active']),'','&amp;');
                curl_setopt($xh, CURLOPT_CUSTOMREQUEST, "PUT");
                $header = array();
                    $header[] = "Cwauth-Token: " . $tok; 
                    curl_setopt($xh, CURLOPT_HTTPHEADER, $header);

                $result = curl_exec($xh);
                if (curl_errno($xh)) {
                    echo 'Error:' . curl_error($xh);
                }


            }


            }

       }



    curl_close ($ch);
    curl_close ($sh);
    curl_close ($wh);
    curl_close ($xh);
?>

有人可以检查我的语法我不知道它运行时它有什么错误它说页面不是workinq。我已经有了ini_set('max_execution_time',0); ini_set('set_time_limit',0);在我的代码中,但没有错误消息一切运行良好,直到我添加PUT,因为我在评论中提到我试图取代[active] =&gt;的值假

这是一个简短的数据结构:

Array
(
    [pathsGroups] => Array
        (
            [0] => Array
                (


                    [paths] => Array
                        (
                            [0] => Array
                                (
                                    [weight] => 100
                                    [active] => 1
                                    [landers] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [lander] => Array
                                                        (
                                                            [id] => 
                                                            [namePostfix] => 
                                                            [name] => 
                                                        )

                                                    [weight] => 100
                                                )

                                        )

                                    [offers] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [offer] => Array
                                                        (
                                                            [id] =>
                                                            [name] => 
                                                            [namePostfix] => 
                                                        )

                                                    [weight] => 100
                                                )

                                        )

                                )

                        )

                    [active] => 1 //this is what i'am trying to replace 
                )

        )



)

0 个答案:

没有答案