-3

Recently our forum is getting flooded by a spammer who always registers with a new identity and sending spam with a link to his website.

The website is already on our blacklist, however, now he is using Google URL shortener to spam (goo.gl/xxxx) and I wanted to ask, if Google is providing an API to resolve the shortened url (in PHP), so we can check if it leads to his website.

Is there already a PHP snipped we can use or a documentation how to prevent spamming using Google shortened links? Else I have to ban goo.gl as well.

UPDATE: Only spammers would downvote this question .!.

lickmycode
  • 2,069
  • 2
  • 19
  • 20

2 Answers2

1

Google does provide an API that allows you to expand URLs, to use it with PHP, simply

function unshorten_url($url) {
    $ch = curl_init('https://www.googleapis.com/urlshortener/v1/url?shortUrl='.$url);
    curl_setopt_array($ch, array(
        CURLOPT_FOLLOWLOCATION => TRUE,
        CURLOPT_RETURNTRANSFER => TRUE,
        CURLOPT_SSL_VERIFYHOST => FALSE,
        CURLOPT_SSL_VERIFYPEER => FALSE, 
    ));

    $json = curl_exec($ch);
    $array = json_decode($json, true);
    return $array['longUrl'];
}

echo unshorten_url('http://goo.gl/XXX');
Ali
  • 3,479
  • 4
  • 16
  • 31
0

Use longurl (http://longurl.org/) api. More details here: https://stackoverflow.com/a/14641055/2055751

Community
  • 1
  • 1
Hungry Mind
  • 226
  • 1
  • 4
  • 12