0

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

AJFMEDIA
  • 2,093
  • 6
  • 29
  • 52
  • It's because `curl_exec` returns `false` with the second website. Use `var_dump($subject);` – Casimir et Hippolyte Jun 01 '18 at 19:36
  • Hi, I have some error handling and it's not returning false. Im checking it for other stings which work. – AJFMEDIA Jun 01 '18 at 19:48
  • 1
    Running the `preg_match()` with the second string hard-coded works correctly. So you're not getting HTML from your curl request, or perhaps this link text is generated dynamically after page load. – WillardSolutions Jun 01 '18 at 19:56
  • ah! The link text is being generated dynamically, that's why I can find it. Thank you! – AJFMEDIA Jun 01 '18 at 20:02

1 Answers1

0

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

AJFMEDIA
  • 2,093
  • 6
  • 29
  • 52