· 5 years ago · Jan 08, 2020, 02:28 PM
1<?php
2// Get your access id and secret key here: https://moz.com/products/api/keys
3ob_start();
4error_reporting(E_ALL ^ E_NOTICE);
5set_time_limit(0);
6
7if (!$_POST['linkcheck']) {
8
9   echo "
10   <h2>Bulk Domain Authority</h2>
11       <form method='POST'>
12           <textarea name='linkcheck' cols=100 rows=30></textarea>
13           <br>
14       <input type=submit>
15   </form>";
16   exit;
17}
18
19$domains = explode("\n",trim($_POST['linkcheck']));
20echo "<br><a href='http://moz.com' rel='nofollow'><img src='http://d2eeipcrcdle6.cloudfront.net/brand-guide/logos/moz_blue.png'></a><br>";
21ob_flush();
22flush();
23$totdomain = count($domains);
24$result = array();
25for ($i=0;$i<$totdomain;$i++){
26    $batchedDomains = array();
27    for ($j=0;$j<10;$j++){
28        $cur = $i + $j;
29        $domain =  trim($domains[$cur]);
30        if($domain != ""){
31            array_push($batchedDomains,$domain);
32        }
33    }
34    array_push($result, get_da($batchedDomains,$i,$filenameda));
35    ob_flush();
36    flush();
37}
38show($result);
39
40
41function get_da($batchedDomains){
42    $accessID = "mozscape-423d5002dc";
43    $secretKey = "2b48bb9d2bd43e5f38766cc937b564d1";
44    $expires = time() + 300;
45    $stringToSign = $accessID."\n".$expires;
46    $binarySignature = hash_hmac('sha1', $stringToSign, $secretKey, true);
47    $urlSafeSignature = urlencode(base64_encode($binarySignature));
48    $cols = "103616137252";
49    $requestUrl = "http://lsapi.seomoz.com/linkscape/url-metrics/?Cols=".$cols."&AccessID=".$accessID."&Expires=".$expires."&Signature=".$urlSafeSignature;
50    $encodedDomains = json_encode($batchedDomains);
51    $options = array(
52       CURLOPT_RETURNTRANSFER => true,
53       CURLOPT_POSTFIELDS     => $encodedDomains
54       );
55    $ch = curl_init($requestUrl);
56    curl_setopt_array($ch, $options);
57    $content = curl_exec($ch);
58    curl_close( $ch );
59    $contents = json_decode($content);
60    $counter =0;
61    return $contents;
62}
63
64function show($content){
65    echo "<table border=2>";
66    echo "<tr><td style='width: 200px;'>URL</td><td>DA</td><td>PA</td></tr>";
67    foreach ($content as $x){
68        foreach ($x as $obj){
69            print_r($obj);
70            $domain = $obj->uu;
71            $da     = $obj->pda;
72            $pa     = $obj->upa;
73            $da     = round($da,2);
74            $pa     = round($pa,2);
75            echo "<tr><td>$domain</td><td>$da</td><td>$pa</td></tr>";
76        }
77    }
78    echo "</table>";
79}
80?>