Postingan lainnya
Mohon untuk memperbaiki fungsi pengulangan
Saya ada script untuk menampilkan list domain untuk menampilkan data DA dan PA yang di keluarkan oleh moz.com
<?php
// Get your access id and secret key here: https://moz.com/products/api/keys
ob_start();
error_reporting(E_ALL ^ E_NOTICE);
set_time_limit(0);
if (!$_POST['linkcheck']) {
echo "
<h2>Bulk Domain Authority</h2>
<form method='POST'>
<textarea name='linkcheck' cols=100 rows=30></textarea>
<br>
<input type=submit>
</form>";
exit;
}
$domains = explode("\n",trim($_POST['linkcheck']));
echo "<br><a href='http://moz.com' rel='nofollow'><img src='http://d2eeipcrcdle6.cloudfront.net/brand-guide/logos/moz_blue.png'></a><br>";
ob_flush();
flush();
$totdomain = count($domains);
$result = array();
for ($i=0;$i<$totdomain;$i++){
$batchedDomains = array();
for ($j=0;$j<10;$j++){
$cur = $i + $j;
$domain = trim($domains[$cur]);
if($domain != ""){
array_push($batchedDomains,$domain);
}
}
array_push($result, get_da($batchedDomains,$i,$filenameda));
ob_flush();
flush();
}
show($result);
function get_da($batchedDomains){
$accessID = "";
$secretKey = "";
$expires = time() + 300;
$stringToSign = $accessID."\n".$expires;
$binarySignature = hash_hmac('sha1', $stringToSign, $secretKey, true);
$urlSafeSignature = urlencode(base64_encode($binarySignature));
$cols = "103616137252";
$requestUrl = "http://lsapi.seomoz.com/linkscape/url-metrics/?Cols=".$cols."&AccessID=".$accessID."&Expires=".$expires."&Signature=".$urlSafeSignature;
$encodedDomains = json_encode($batchedDomains);
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => $encodedDomains
);
$ch = curl_init($requestUrl);
curl_setopt_array($ch, $options);
$content = curl_exec($ch);
curl_close( $ch );
$contents = json_decode($content);
$counter =0;
return $contents;
}
function show($content){
echo "<table border=2>";
echo "<tr><td style='width: 200px;'>URL</td><td>DA</td><td>PA</td></tr>";
foreach ($content as $x){
foreach ($x as $obj){
$domain = $obj->uu;
$da = $obj->pda;
$pa = $obj->upa;
$da = round($da,2);
$pa = round($pa,2);
echo "<tr><td>$domain</td><td>$da</td><td>$pa</td></tr>";
}
}
echo "</table>";
}
?>
Ketika di coba hasilnya berhasil keluar namun terjadi pengulangan list domain,DA, dan PA sampai 4 kali.
Mohon bantuan di mana salah kodenya. Saya sudah coba utak-atik kode dibagian pengulangan tidak mendapatkan hasil
0
1 Jawaban:
Saya baru ngecek sampe kode ini
<pre> for ($i=0;$i<$totdomain;$i++){ </pre>
0