ph-7/php-http-response-header
一个简单的PHP应用程序发送HTTP响应头包
v1.0.3
2023-08-12 05:09 UTC
Requires
- php: >=8.0
- ph-7/just-http-status-codes: ^1.1
Requires (Dev)
- phpunit/phpunit: ^10.2
README
一个简单的PHP包,可以轻松向浏览器发送正确的HTTP响应头 🐘
⚙️需求
- PHP v8.0 或更高版本 🚀
📦安装
将此库添加到项目的最简单方法是通过Composer
composer require ph-7/php-http-response-header
🪄用法 - 示例
通过HTTP状态码发送头部
use PH7\PhpHttpResponseHeader\Header; // Sends "200 OK" header to the browser Http::setHeadersByCode(200); // ... // Send "201 Created" header Http::setHeadersByCode(201); // ... // Sends "404 Not Found" to the browser Http::setHeadersByCode(404); // ... // Sends "400 Bad Request" header to the browser Http::setHeadersByCode(400); // and so on ...
但是,该库还有许多其他实用方法,如下所示
维护代码
use PH7\PhpHttpResponseHeader\Header; // Send 503, Service Temporarily Unavailable to the browser mentioning that you are doing a maintenance (good practice!) Http::setMaintenanceCode($maintenanceTimeSeconds: 360);
获取HTTP协议
use PH7\PhpHttpResponseHeader\Header; // The HTTP server protocol Http::getProtocol()
设置内容类型
use PH7\PhpHttpResponseHeader\Header; // Send "Content-Type: application/json" header to the browser Http::setContentType('application/json'); // Send "Content-type: text/xml" to the browser Http::setContentType('text/xml');
🧑🍳谁做的这个?
Pierre-Henry Soria。一位超级热情和热情的软件工程师!🚀真正的奶酪🧀,咖啡和巧克力爱好者!😋在PH7.me 💫找到我
☕️你喜欢它吗?给我一杯咖啡,同时提升软件开发!💪
🎥我在构建此包
👉点击此处观看YouTube视频,从头到尾构建此包。
⚖️许可证
PHP HTTP响应慷慨地分发了MIT许可证🎉享受!