Skip to content

A simple package to send HTTP header responses ✨

License

Notifications You must be signed in to change notification settings

pH-7/php-http-header-response

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Oct 21, 2024
04f84cf Β· Oct 21, 2024

History

44 Commits
Jun 11, 2023
Aug 20, 2023
Aug 20, 2023
Jun 9, 2023
Aug 21, 2023
Jun 9, 2023
Oct 21, 2024
Aug 20, 2023
Jul 2, 2023

Repository files navigation

PHP HTTP Response Headers

Simple PHP package to easily send the right HTTP header responses to the browser 🐘

βš™οΈ Requirement

πŸ“¦ Installation

The simplest way to add this library to your project, is with Composer

composer require ph-7/php-http-response-header

πŸͺ„ Usage - Examples

Send Header By HTTP Code

use PH7\PhpHttpResponseHeader\Header;

// Sends "200 OK" header to the browser
Http::setHeadersByCode(200);

// ...

// Send "201 Created" header
Http::setHeadersByCode(201);

// ...

// Sends "404 Not Found" to the browser
Http::setHeadersByCode(404);

// ...

// Sends "400 Bad Request" header to the browser
Http::setHeadersByCode(400);


// and so on ...

But, the library has many more handy methods such as below:

Maintenance Code

use PH7\PhpHttpResponseHeader\Header;

// Send 503, Service Temporarily Unavailable to the browser mentioning that you are doing a maintenance (good practice!)
Http::setMaintenanceCode($maintenanceTimeSeconds: 360);

Get HTTP Protocol

use PH7\PhpHttpResponseHeader\Header;

//  The HTTP server protocol
Http::getProtocol()

Set Content Type

use PH7\PhpHttpResponseHeader\Header;

// Send "Content-Type: application/json" header to the browser
Http::setContentType('application/json');

// Send "Content-type: text/xml" to the browser
Http::setContentType('text/xml');

πŸ§‘β€πŸ³ Who baked this?

Pierre-Henry Soria

Pierre-Henry Soria. A super passionate and enthusiastic software engineer! πŸš€ True cheese πŸ§€ , coffee, and chocolate lover! πŸ˜‹ Reach me at PH7.me πŸ’«

β˜•οΈ Are you enjoying it? Offer me a coffee and boost the software development at the same time! πŸ’ͺ

@phenrysay pH-7

πŸŽ₯ Me building this package

Watch the video

πŸ‘‰ Click here to watch on YouTube, me building this package from A to Z.

βš–οΈ License

PHP HTTP Response is generously distributed under the MIT πŸŽ‰ Enjoy!