spatie/mixed-content-scanner
Composer 安装命令:
composer require spatie/mixed-content-scanner
包简介
Scan your site for mixed content
README 文档
README
This package contains a class that can scan your site for 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.
Support us
Learn how to create a package like this one, by watching our premium video course:
We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.
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. We publish all received postcards on our virtual postcard wall.
Installation
You can install the package via composer:
composer require spatie/mixed-content-scanner
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:srcembed:srcform:actionlink:hrefiframe:srcimg:src,srcsetobject:dataparam:valuescript:srcsource:src,srcsetvideo: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 <script> or <style> and shortlinks into consideration.
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 ofsrcorsrcsetfor aformthis can be the value ofaction, ...$foundOnUrl: the url where the mixed content was found
Customizing the requests
The scanner is powered by our homegrown Crawler which on it's turn leverages Guzzle 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
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
The scanner is powered by our homegrown 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
Please see CHANGELOG for more information what has changed recently.
Testing
composer test
Contributing
Please see CONTRIBUTING for details.
Security
If you've found a bug regarding security please mail security@spatie.be instead of using the issue tracker.
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.
Credits
The scanner is inspired by mixed-content-scan by Bram Van Damme. Parts of his readme and code were used.
License
The MIT License (MIT). Please see License File for more information.
spatie/mixed-content-scanner 适用场景与选型建议
spatie/mixed-content-scanner 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 40.25k 次下载、GitHub Stars 达 104, 最近一次更新时间为 2014 年 12 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「spatie」 「mixed-content-scanner」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 spatie/mixed-content-scanner 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 spatie/mixed-content-scanner 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 spatie/mixed-content-scanner 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Receive webhooks in Laravel apps
Easily optimize images using PHP
Store your application settings
Add tags and taggable behaviour to your Laravel app
Speed up a Laravel application by caching the entire response additions
Manage events on a Google Calendar
统计信息
- 总下载量: 40.25k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 105
- 点击次数: 34
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-12-15