CodeIgniter 4 PHP
一个用于 CodeIgniter 4 的 PHP 代码片段,以空 GIF 响应对 /pixel.gif 的请求,GIF 在启动时只解码一次。
CodeIgniter 4 PHP
<?php
// app/Config/Routes.php
use CodeIgniter\Router\RouteCollection;
/** @var RouteCollection $routes */
$routes->get('/', 'Home::index');
$routes->get('/pixel.gif', static fn () => service('response')
->setContentType('image/gif', '')
->setHeader('Cache-Control', 'no-store')
->setBody(base64_decode('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==')));
我们运行了此代码片段,并比对了它返回的字节。
验证
curl -sI http://localhost:8080/pixel.gif