emptygif
Language: English

All languages and frameworks

CodeIgniter 4 PHP

A PHP snippet for CodeIgniter 4 that answers requests for /pixel.gif with the empty GIF, decoded once at startup.

CodeIgniter 4 PHP

Install
composer create-project codeigniter4/appstarter my-app
File
Routes.php
Run
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==')));

We ran this snippet and compared the bytes it returned.

Check it

curl -sI http://localhost:8080/pixel.gif

Official site: CodeIgniter 4

More in PHP