emptygif
언어: 한국어

모든 언어 및 프레임워크

Plain PHP (php-fpm, mod_php, php -S) PHP

/pixel.gif 요청에 빈 GIF로 응답하는 Plain PHP (php-fpm, mod_php, php -S)용 PHP 스니펫입니다. GIF는 시작할 때 한 번만 디코딩합니다.

Plain PHP (php-fpm, mod_php, php -S) PHP

파일
index.php
실행
php -S 0.0.0.0:8080 index.php
<?php

// Front controller: works under php-fpm, Apache mod_php or the built-in server.
if (parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) !== '/pixel.gif') {
    http_response_code(404);
    return;
}

$gif = base64_decode('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==');

header('Content-Type: image/gif');
header('Content-Length: ' . strlen($gif));
header('Cache-Control: no-store');
echo $gif;

이 스니펫은 실행해 보고, 반환된 바이트를 비교했습니다.

확인

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

공식 사이트: Plain PHP (php-fpm, mod_php, php -S)

PHP의 다른 예제