phpcurlpreg-matchpreg-match-allstripos

Search HTML source for string of 'cdn' after CURL request


I want to try an establish if a website is using a CDN. It's a little wooly but I just want to check if the sourcecode contains 'cdn', based on that I can assume the site is using one. - Terrible I know. Unsure of any other menthod.

This is what I have

$url = $_GET['url'];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
$subject = curl_exec($ch);
curl_close($ch);

//cdn check
if (preg_match("/(cdn)/", $subject)) {
    $cdn = true;
} else {
    $cdn = false;
}

It worked when checking a website containing this HTML:

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">

But failed when checking a website containing this HTML:

<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.0.3/cookieconsent.min.css" />

Dispite 'cdn' being in both.

Any ideas? Thanks


Solution

  • The second website was returning html, but the links were dynamically inserted after page load so were not being returned in the html via curl