emptygif
語言: 繁體中文

所有語言和框架

CodeIgniter 4 PHP

適用於 CodeIgniter 4 的 PHP 程式碼片段,以空 GIF 回應對 /pixel.gif 的請求,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 範例