curl semrush php API display_date

21
March 14, 2019, at 9:00 PM

i have this API request everything is working fine but two things thing when i add the display_date to the url the localhost and the hosting server give me this error efoodsdirect.com ERROR 612 :: Invalid display_date parameter, must be in format YYYYMM15 or it should be skipped. second is when i get the needed data it should be stored in a csv file but the file i download is always empty how can solve these problems? >

<body> 
    <?php 
error_reporting(E_ALL); 
ini_set('ignore_errors', true); 
set_time_limit(0); 
$database = "au"; 
$key = "xxxxxxxxxxxxxxxxxxxxxxxxx"; 
$fname = "results-au.csv"; 
 
function getValues($domain,$date='') { 
    global $database,$key; 
    $keywords = $traffic = 0; 
    $curl = curl_init(); 
     
    curl_setopt_array($curl, array(   
      CURLOPT_URL => "http://api.semrush.com/?type=domain_ranks&key=$key&display_date={$date}&export_columns=Ot&domain=$domain", 
      CURLOPT_RETURNTRANSFER => true, 
      CURLOPT_TIMEOUT => 30, 
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, 
      CURLOPT_CUSTOMREQUEST => "POST", 
      CURLOPT_HTTPHEADER => array( 
        "cache-control: no-cache" 
      ), 
    )); 
    $reply = curl_exec($curl); 
     
    $err = curl_error($curl); 
     
    curl_close($curl); 
    echo $reply; 
     
     
} 
?> 
<?php 
 
 
// got file  
if(@$_FILES["infile"]["size"] AND @$_POST['date']) { 
	$tFile=tempnam("/tmp","dom"); 
	if(!move_uploaded_file($_FILES["infile"]["tmp_name"],$tFile)) 
		die("Can not move upload file"); 
		 
	$domains=array_filter(array_map("trim",file($tFile)));	 
	$date= date("y-m",strtotime($_POST['date']))."15."; 
	 
	$csvF=fopen($fname,"wb+"); 
	if(!$csvF) 
		die("Can not open $fname"); 
	//fwrite($csvF, "Domain,$_POST[date] Seo Traffic\n"); 
		$csv_html ="Domain,$_POST[date] Seo Traffic\n"; 
$i=1; 
	foreach($domains as $domain) { 
		echo $i; echo " <h5>$domain</h5>"; 
		//$today = getValues($domain); 
		$reply = getValues($domain,$date); 
        if (is_array($reply)) { 
            $domainTraffic = $reply[0]; 
            echo '<h4>Ok: ' . $domainTraffic . '</h4>'; 
        } else { 
            $domainTraffic = ''; 
            echo "<p class=\"error\">{$reply}</p>"; 
        } 
 
      $csv_html .="$domain,$domainTraffic\n"; 
 
        flush(); 
if($i%1000==0){ 
  fwrite($csvF, $csv_html); 
$csv_html=""; 
sleep(10); 
} 
$i++; 
	} 
 
	fclose($csvF); 
	echo "<h1><a href=$fname target=_blank>Download file</a></h1>"; 
} else { 
    ?> 
        <div> 
            <form  method="post" enctype="multipart/form-data"> 
                SE Traffic for  Date entered by user 
                <hr> 
                Report Date:<input type=text size=12 name=date value="<?php echo date("Y-M-15",strtotime("-1 months"))?>"> (required!)<br> 
                File (txt or csv, one domain per line):<input type=file name=infile><br><br> 
                <input type=submit value="Start"> 
            </form> 
        </div> 
    <?php 
} 
?> 
</body> 
</html>

READ ALSO
Bypass Session Validations php

Bypass Session Validations php

Can Anyone bypass my Login page if they can bypass it how they well do it

15
PHP Exec iptables

PHP Exec iptables

I would like exec iptables from PHP

19
Can`t parse site on php [duplicate]

Can`t parse site on php [duplicate]

This question already has an answer here:

48