emptygif
言語: 日本語

すべての言語・フレームワーク

CodeIgniter 4 PHP

/pixel.gif へのリクエストに空の GIF を返す、CodeIgniter 4 用の PHP スニペット。GIF は起動時に一度だけデコードします。

CodeIgniter 4 PHP

インストール
composer create-project codeigniter4/appstarter my-app
ファイル
Routes.php
実行
php spark serve
<?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

公式サイト: CodeIgniter 4

PHP の他の例