virdiggg/header-ci3
Composer 安装命令:
composer require virdiggg/header-ci3
包简介
HTTP Header for CodeIgniter 3
README 文档
README
Is helmetjs/helmet for CodeIgniter 3/PHP.
HOW TO USE
- Install this library with composer
composer require virdiggg/header-ci3
- Load this library on your
application/config/config.phpor you can create a controller if you don't want to load this on all of your website. Example isapplication/controller/App.php
<?php defined('BASEPATH') or exit('No direct script access allowed');
use Virdiggg\HeaderCi3\Headers;
class App extends CI_Controller
{
private $headers;
public function __construct()
{
parent::__construct();
}
public function testing1()
{
$this->headers = new Headers();
$this->headers->setHeaders();
return;
}
public function testing2()
{
$this->headers = new Headers();
$this->headers->setContentSecurityPolicy(["default-src 'self'"]);
$this->headers->setHeaders();
echo 1;
return;
}
public function testing3()
{
$this->headers = new Headers();
$this->headers->setXDNSPrefetchControl('on');
$this->headers->setHeaders();
echo 1;
return;
}
public function test_header()
{
$this->headers = new Headers();
echo 1;
return;
}
public function test_no_header()
{
echo 1;
return;
}
}
- Then CURL your website in cmd
curl -I http://localhost/codeigniter/app/test_header/
HTTP/1.1 200 OK
Date: Fri, 08 Sep 2023 00:00:00 GMT
Server: Apache/2.4.54 (Win64) OpenSSL/1.1.1q PHP/8.1.10
Content-Type: text/html; charset=UTF-8
curl -I http://localhost/codeigniter/app/test_no_header/
HTTP/1.1 200 OK
Date: Fri, 08 Sep 2023 00:00:00 GMT
Server: Apache/2.4.54 (Win64) OpenSSL/1.1.1q PHP/8.1.10
X-Powered-By: PHP/8.1.10
Content-Type: text/html; charset=UTF-8
curl -I http://localhost/codeigniter/app/testing1/
HTTP/1.1 200 OK
Date: Fri, 08 Sep 2023 00:00:00 GMT
Server: Apache/2.4.54 (Win64) OpenSSL/1.1.1q PHP/8.1.10
Content-Security-Policy: default-src 'self' base-uri 'self' font-src 'self' https: data: form-action 'self' frame-ancestors 'self' img-src 'self' data: object-src 'none' script-src 'self' script-src-attr 'none' style-src 'self' https: 'unsafe-inline' upgrade-insecure-requests
'unsafe-inline' *.gstatic.com *.googleapis.com *.jquery.com *.jsdelivr.net
Cross-Origin-Opener-Policy: same-origin
Cross-Origin-Resource-Policy: same-origin
Cross-Origin-Embedder-Policy: require-corp
Origin-Agent-Cluster: ?1
Referrer-Policy: no-referrer
X-Content-Type-Options: nosniff
X-DNS-Prefetch-Control: off
X-Download-Options: noopen
X-Frame-Options: SAMEORIGIN
X-Permitted-Cross-Domain-Policies: none
X-XSS-Protection: 0
Permissions-Policy: fullscreen=(self), geolocation=(self), camera=(self)
Strict-Transport-Security: max-age=15552000; includeSubDomains
Content-Type: text/html; charset=UTF-8
curl -I http://localhost/codeigniter/app/testing2/
HTTP/1.1 200 OK
Date: Fri, 08 Sep 2023 00:00:00 GMT
Server: Apache/2.4.54 (Win64) OpenSSL/1.1.1q PHP/8.1.10
Content-Security-Policy: default-src 'self'
Cross-Origin-Opener-Policy: same-origin
Cross-Origin-Resource-Policy: same-origin
Cross-Origin-Embedder-Policy: require-corp
Origin-Agent-Cluster: ?1
Referrer-Policy: no-referrer
X-Content-Type-Options: nosniff
X-DNS-Prefetch-Control: off
X-Download-Options: noopen
X-Frame-Options: SAMEORIGIN
X-Permitted-Cross-Domain-Policies: none
X-XSS-Protection: 0
Permissions-Policy: fullscreen=(self), geolocation=(self), camera=(self)
Strict-Transport-Security: max-age=15552000; includeSubDomains
Content-Type: text/html; charset=UTF-8
curl -I http://localhost/codeigniter/app/testing3/
HTTP/1.1 200 OK
Date: Fri, 08 Sep 2023 00:00:00 GMT
Server: Apache/2.4.54 (Win64) OpenSSL/1.1.1q PHP/8.1.10
Content-Security-Policy: default-src 'self' base-uri 'self' font-src 'self' https: data: form-action 'self' frame-ancestors 'self' img-src 'self' data: object-src 'none' script-src 'self' script-src-attr 'none' style-src 'self' https: 'unsafe-inline' upgrade-insecure-requests
'unsafe-inline' *.gstatic.com *.googleapis.com *.jquery.com *.jsdelivr.net
Cross-Origin-Opener-Policy: same-origin
Cross-Origin-Resource-Policy: same-origin
Cross-Origin-Embedder-Policy: require-corp
Origin-Agent-Cluster: ?1
Referrer-Policy: no-referrer
X-Content-Type-Options: nosniff
X-DNS-Prefetch-Control: on
X-Download-Options: noopen
X-Frame-Options: SAMEORIGIN
X-Permitted-Cross-Domain-Policies: none
X-XSS-Protection: 0
Permissions-Policy: fullscreen=(self), geolocation=(self), camera=(self)
Strict-Transport-Security: max-age=15552000; includeSubDomains
Content-Type: text/html; charset=UTF-8
EXPLANATIONS
- Header
X-Powered-Bywill always be removed once you load this library. - This will use all the default HTTP Headers
$this->headers = new Headers();
$this->headers->setHeaders();
- This will modify
Content-Security-Policyheader, a powerful allow-list of what can happen on your page which mitigates many attacks. Be careful when using this as this can break your page if you're using 3rd party library such as FontAwesome. Parameter is an array.
$this->headers = new Headers();
$this->headers->setContentSecurityPolicy([array]);
$this->headers->setHeaders();
- This will modify
Cross-Origin-Opener-Policyheader, it helps process-isolate your page. Parameter is a string.
$this->headers = new Headers();
$this->headers->setCrossOriginOpenerPolicy('string');
$this->headers->setHeaders();
- This will modify
Cross-Origin-Resource-Policyheader, it blocks others from loading your resources cross-origin. Parameter is a string.
$this->headers = new Headers();
$this->headers->setCrossOriginResourcePolicy('string');
$this->headers->setHeaders();
- This will modify
Cross-Origin-Embedder-Policyheader, it configures embedding cross-origin resources into the document. Parameter is a string.
$this->headers = new Headers();
$this->headers->setCrossOriginResourcePolicy('string');
$this->headers->setHeaders();
- This will modify
Origin-Agent-Clusterheader, it changes process isolation to be origin-based. Parameter is a string.
$this->headers = new Headers();
$this->headers->setOriginAgentCluster('string');
$this->headers->setHeaders();
- This will modify
Referrer-Policyheader, it controls the Referer header. Parameter is a string.
$this->headers = new Headers();
$this->headers->setReferrerPolicy('string');
$this->headers->setHeaders();
- This will modify
Strict-Transport-Securityheader, it tells browsers to prefer HTTPS. Parameter is a string. - Make sure whether you have CONST ENVIRONMENT or not, if you are not, this will create it's own ENVIRONMENT.
- If ENVIRONMENT = 'production' (most likely not localhost), it will add this header. Otherwise, no.
$this->headers = new Headers();
$this->headers->setStrictTransportSecurity('string');
$this->headers->setHeaders();
- This will modify
X-Content-Type-Optionsheader, it help avoids MIME sniffing. Parameter is a string.
$this->headers = new Headers();
$this->headers->setXContentTypeOptions('string');
$this->headers->setHeaders();
- This will modify
X-DNS-Prefetch-Controlheader, it controls DNS prefetching. Parameter is a string.
$this->headers = new Headers();
$this->headers->setXDNSPrefetchControl('string');
$this->headers->setHeaders();
- This will modify
X-Download-Optionsheader, it forces downloads to be saved (Internet Explorer only). Parameter is a string.
$this->headers = new Headers();
$this->headers->setXDownloadOptions('string');
$this->headers->setHeaders();
- This will modify
X-Frame-Optionsheader, a legacy header that mitigates clickjacking attacks. Parameter is a string.
$this->headers = new Headers();
$this->headers->setXFrameOptions('string');
$this->headers->setHeaders();
- This will modify
X-Permitted-Cross-Domain-Policiesheader, it controls cross-domain behavior for Adobe products, like Acrobat. Parameter is a string.
$this->headers = new Headers();
$this->headers->setXPermittedCrossDomainPolicies('string');
$this->headers->setHeaders();
- This will modify
X-XSS-Protectionheader, a legacy header that tries to mitigate XSS attacks, but makes things worse, so we disables it. Parameter is a string.
$this->headers = new Headers();
$this->headers->setXXSSProtection('string');
$this->headers->setHeaders();
- This will modify
Permissions-Policyheader, it provides mechanisms for web developers to explicitly declare what functionality can and cannot be used on a website. Parameter is a string.
$this->headers = new Headers();
$this->headers->setPermissionPolicy('string');
$this->headers->setHeaders();
virdiggg/header-ci3 适用场景与选型建议
virdiggg/header-ci3 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 24 次下载、GitHub Stars 达 1, 最近一次更新时间为 2023 年 09 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 virdiggg/header-ci3 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 virdiggg/header-ci3 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 24
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 10
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-09-08