PHPackages                             spatie/mixed-content-scanner - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. spatie/mixed-content-scanner

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

spatie/mixed-content-scanner
============================

Scan your site for mixed content

5.0.0(2y ago)10438.5k↑137.5%183MITPHPPHP ^8.1CI failing

Since Dec 15Pushed 5mo ago5 watchersCompare

[ Source](https://github.com/spatie/mixed-content-scanner)[ Packagist](https://packagist.org/packages/spatie/mixed-content-scanner)[ Docs](https://github.com/spatie/mixed-content-scanner)[ GitHub Sponsors](https://github.com/spatie)[ RSS](/packages/spatie-mixed-content-scanner/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (3)Versions (32)Used By (3)

Scan your site for mixed content
================================

[](#scan-your-site-for-mixed-content)

[![Latest Version on Packagist](https://camo.githubusercontent.com/71fa31547f82ea497c1edb7b7551d72bade5acd15ca77629a76c1f4c725611c3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7370617469652f6d697865642d636f6e74656e742d7363616e6e65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/mixed-content-scanner)[![Tests](https://github.com/spatie/mixed-content-scanner/workflows/Tests/badge.svg)](https://github.com/spatie/mixed-content-scanner/workflows/Tests/badge.svg)[![Total Downloads](https://camo.githubusercontent.com/f2584a0e35117f98c61c765c64acde60c2cd8d1db123b27d0429fa3649785e0a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7370617469652f6d697865642d636f6e74656e742d7363616e6e65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/mixed-content-scanner)

This package contains a class that can scan your site for [mixed content](https://developer.mozilla.org/en-US/docs/Web/Security/Mixed_content).

Here's an example of how you can use it:

```
use Spatie\MixedContentScanner\MixedContentScanner;

$logger = new MixedContentLogger();

$scanner = new MixedContentScanner($logger);

$scanner->scan('https://example.com');
```

`MixedContentLogger` is a class containing methods that get called when mixed content is (not) found.

If you don't need a custom implementation but simply want to look for mixed content using a command line tool, take a look at [our mixed-content-scanner-cli package](https://github.com/spatie/mixed-content-scanner-cli).

Support us
----------

[](#support-us)

Learn how to create a package like this one, by watching our premium video course:

[![Laravel Package training](https://camo.githubusercontent.com/4c7f3720a29525e627f6004ee367e55def510e45d18e6bc974725812fa5cf257/68747470733a2f2f7370617469652e62652f6769746875622f7061636b6167652d747261696e696e672e6a7067)](https://laravelpackage.training)

We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require spatie/mixed-content-scanner
```

How it works under the hood
---------------------------

[](#how-it-works-under-the-hood)

When scanning a site, the scanner will crawl everypage. On the retrieve html, these elements and attributes will be checked:

- `audio`: `src`
- `embed`: `src`
- `form`: `action`
- `link`: `href`
- `iframe`: `src`
- `img`: `src`, `srcset`
- `object`: `data`
- `param`: `value`
- `script`: `src`
- `source`: `src`, `srcset`
- `video`: `src`

If any of those attributes start with `http://` the element will be regarded as mixed content.

The package does not scan linked `.css` or `.js` files, nor does it take inline `` or `` and [shortlinks](http://microformats.org/wiki/rel-shortlink) into consideration.

Usage
-----

[](#usage)

```
use Spatie\MixedContentScanner\MixedContentScanner

$logger = new MixedContentLogger();

$scanner = new MixedContentScanner($logger);

$scanner->scan('https://example.com');
```

That `MixedContentScanner` accepts an instance of a class that extends `\Spatie\MixedContentScannerMixedContentObserver`. You should create such a class yourself. Let's take a look at an example implementation.

```
use Psr\Http\Message\UriInterface;
use Spatie\MixedContentScanner\MixedContent;
use Spatie\MixedContentScanner\MixedContentObserver;

class MyMixedContentLogger extends MixedContentObserver
{
    /**
     * Will be called when mixed content was found.
     *
     * @param \Spatie\MixedContentScanner\MixedContent $mixedContent
     */
    public function mixedContentFound(MixedContent $mixedContent): void
    {
    }

    /**
     * Will be called when no mixed content was found on the given url.
     *
     * @param \Psr\Http\Message\UriInterface $crawledUrl
     */
    public function noMixedContentFound(UriInterface $crawledUrl): void
    {
    }

    /**
     * Will be called when the scanner has finished crawling.
     */
    public function finishedCrawling(): void
    {
    }
}
```

Of course, you should supply a function body to these methods yourself. If you don't need a function just leave it off.

The `$mixedContent` variable the `mixedContentFound` class accept is an instance of `\Spatie\MixedContentScanner\MixedContent` which has these three properties:

- `$elementName`: the name of the element that is regarded as mixed content
- `$mixedContentUrl`: the url of the element that is regarded as mixed content. For an image this can be the value of `src` or `srcset` for a `form` this can be the value of `action`, ...
- `$foundOnUrl`: the url where the mixed content was found

### Customizing the requests

[](#customizing-the-requests)

The scanner is powered by [our homegrown Crawler](https://github.com/spatie/crawler) which on it's turn leverages [Guzzle](http://docs.guzzlephp.org/en/stable/) to perform webrequests. You can pass an array of options to the second argument of `MixedContentScanner`. These options will be passed to the Guzzle Client.

Here's an example where ssl verification is being turned off.

```
$scanner = new MixedContentScanner($logger);
$scanner->scan('https://laravel.com', ['verify' => 'false']);
```

### Filtering the crawled urls

[](#filtering-the-crawled-urls)

By default, the mixed content scanner will crawl all urls of the hostname given. If you want to filter the urls to be crawled, you can pass the scanner a class that extends `Spatie\Crawler\CrawlProfile`.

Here's the content of that class:

```
namespace Spatie\Crawler;

use Psr\Http\Message\UriInterface;

abstract class CrawlProfile
{
    /**
     * Determine if the given url should be crawled.
     *
     * @param \Psr\Http\Message\UriInterface $url
     *
     * @return bool
     */
    abstract public function shouldCrawl(UriInterface $url): bool;
}
```

And here's how you can let the scanner use your profile:

```
use Spatie\MixedContentScanner\MixedContentScanner;

$logger = new MixedContentLogger();

$scanner = new MixedContentScanner($logger);

$scanner->setCrawlProfile(new MyCrawlProfile);
```

Customizing the crawler
-----------------------

[](#customizing-the-crawler)

The scanner is powered by [our homegrown Crawler](https://github.com/spatie/crawler). You can call any methods on the crawler before the crawling process starts by calling `configureCrawler` on a `MixedContentScanner`.

```
use Spatie\Crawler\Crawler;
use Spatie\MixedContentScanner\MixedContentScanner;

$scanner = (new MixedContentScanner($logger))
    ->configureCrawler(function(Crawler $crawler) {
        $crawler->setConcurrency(1) // now all urls will be crawled one by one
    });
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Testing
-------

[](#testing)

```
composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you've found a bug regarding security please mail  instead of using the issue tracker.

Postcardware
------------

[](#postcardware)

You're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.

Our address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium.

We publish all received postcards [on our company website](https://spatie.be/en/opensource/postcards).

Credits
-------

[](#credits)

- [Freek Van der Herten](https://github.com/freekmurze)
- [All Contributors](../../contributors)

The scanner is inspired by [mixed-content-scan](https://github.com/bramus/mixed-content-scan) by [Bram Van Damme](https://github.com/bramus). Parts of his readme and code were used.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

54

—

FairBetter than 97% of packages

Maintenance48

Moderate activity, may be stable

Popularity45

Moderate usage in the ecosystem

Community27

Small or concentrated contributor base

Maturity83

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 78.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~103 days

Recently: every ~224 days

Total

31

Last Release

1079d ago

Major Versions

0.8.7 → 1.0.02017-08-03

1.2.1 → 2.0.02017-12-22

2.1.1 → 3.0.02018-03-01

3.3.0 → 4.0.02020-09-29

4.0.4 → 5.0.02023-06-04

PHP version history (5 changes)0.7PHP &gt;=5.4

0.8.3PHP ^7.1

4.0.0PHP ^7.4

4.0.1PHP ^7.4|^8.0

5.0.0PHP ^8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7535935?v=4)[Spatie](/maintainers/spatie)[@spatie](https://github.com/spatie)

---

Top Contributors

[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (132 commits)")[![brendt](https://avatars.githubusercontent.com/u/6905297?v=4)](https://github.com/brendt "brendt (10 commits)")[![AdrianMrn](https://avatars.githubusercontent.com/u/12762044?v=4)](https://github.com/AdrianMrn "AdrianMrn (8 commits)")[![SamuelNitsche](https://avatars.githubusercontent.com/u/24483576?v=4)](https://github.com/SamuelNitsche "SamuelNitsche (8 commits)")[![WaveHack](https://avatars.githubusercontent.com/u/1611537?v=4)](https://github.com/WaveHack "WaveHack (3 commits)")[![akoepcke](https://avatars.githubusercontent.com/u/5311185?v=4)](https://github.com/akoepcke "akoepcke (2 commits)")[![AlexVanderbist](https://avatars.githubusercontent.com/u/6287961?v=4)](https://github.com/AlexVanderbist "AlexVanderbist (2 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (1 commits)")[![codeinnovers](https://avatars.githubusercontent.com/u/25947503?v=4)](https://github.com/codeinnovers "codeinnovers (1 commits)")[![sebastiandedeyne](https://avatars.githubusercontent.com/u/1561079?v=4)](https://github.com/sebastiandedeyne "sebastiandedeyne (1 commits)")[![thecaliskan](https://avatars.githubusercontent.com/u/13554944?v=4)](https://github.com/thecaliskan "thecaliskan (1 commits)")

---

Tags

httpsmixed-content-errorscanspatiemixed-content-scanner

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/spatie-mixed-content-scanner/health.svg)

```
[![Health](https://phpackages.com/badges/spatie-mixed-content-scanner/health.svg)](https://phpackages.com/packages/spatie-mixed-content-scanner)
```

###  Alternatives

[spatie/laravel-package-tools

Tools for creating Laravel packages

945125.5M7.0k](/packages/spatie-laravel-package-tools)[spatie/laravel-data

Create unified resources and data transfer objects

1.8k28.9M627](/packages/spatie-laravel-data)[spatie/macroable

A trait to dynamically add methods to a class

72759.6M64](/packages/spatie-macroable)[spatie/regex

A sane interface for php's built in preg\_\* functions

1.1k17.1M59](/packages/spatie-regex)[spatie/enum

PHP Enums

84529.1M68](/packages/spatie-enum)[spatie/laravel-settings

Store your application settings

1.5k5.9M72](/packages/spatie-laravel-settings)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
