Download the PHP package iviphp/http without Composer

On this page you can find all versions of the php package iviphp/http. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package http

Ivi HTTP

HTTP request, response, header and uploaded-file primitives for the IviPHP ecosystem.

Overview

iviphp/http provides the low-level HTTP objects used by IviPHP applications and packages.

The package includes:

This package does not provide routing, middleware execution or application bootstrapping. Those responsibilities belong to higher-level IviPHP components.

Installation

Requirements

Request

Create a request manually:

Create a request from PHP superglobals:

Request::fromGlobals() reads:

Optional arguments can be passed for isolated tests.

Request method and URI

The request path is not automatically URL-decoded. This preserves encoded path separators and avoids changing security-sensitive URI data.

Request headers

Header names are case-insensitive.

All three calls resolve the same header.

Content type and authentication

contentType() removes parameters such as the character set.

becomes:

Query parameters

Nested query values can be accessed with dot notation.

Parsed request body

Dot notation is available when the parsed body is an array.

JSON requests

Invalid JSON throws an InvalidArgumentException containing the original JsonException.

Check the media type before expecting JSON:

Combined input

Query parameters and body values can be accessed through one interface.

Body values override query values when the same key exists.

Cookies

Cookie values are untrusted user input and must be validated before use.

Server values

isSecure() checks the direct PHP server environment.

Forwarded headers such as X-Forwarded-Proto are intentionally not trusted automatically. Proxy trust must be configured by a higher-level application component.

Request attributes

Request attributes can store routing and middleware data.

Request transformation methods return a new request.

The original request is not modified.

Uploaded files

Retrieve an uploaded file:

Check whether an upload entry exists:

Multiple and nested PHP upload arrays are normalized automatically.

A nested upload may return an array containing multiple UploadedFile instances.

Creating an UploadedFile

From a PHP $_FILES entry:

For tests and internal file processing:

Files created with fromPath() are not treated as genuine PHP HTTP uploads.

Upload validity

A genuine HTTP upload is considered valid only when:

Uploaded filename security

The original filename is available through:

The client-provided filename must never be used directly as a filesystem path.

Use the sanitized filename instead:

Provide a fallback when necessary:

The client extension can be retrieved with:

The extension is still client-controlled and must not be used as the only validation mechanism.

Media-type validation

The client-provided type is available through:

This value is not trustworthy.

Detect the media type from the file contents:

Validate against accepted types:

Wildcard families are supported:

Content-based media-type detection requires the PHP Fileinfo extension.

Upload size validation

Retrieve the real filesystem size:

Retrieve the client-declared size:

Validate the maximum accepted size:

The example allows files up to 5 MiB.

Server limits such as upload_max_filesize and post_max_size must also be configured correctly.

Upload checksums

Calculate a SHA-256 checksum:

Use another supported hash algorithm:

Checksums can help with:

A checksum does not replace malware scanning or media validation.

Reading uploaded files

Open the uploaded file as a binary stream:

Streaming avoids loading large files entirely into memory.

Moving uploaded files

Existing files are not overwritten by default.

Optional permissions can be applied:

The destination directory must already exist and be writable.

After movement:

path() returns the temporary path before movement and the final path afterward.

An uploaded file cannot be moved twice.

Upload compression

Compression is explicit and optional.

Select a Gzip compression level from 0 to 9:

Allow replacement of an existing compressed file:

Compression creates a compressed copy and does not move or delete the source upload.

Automatic compression is intentionally avoided. Formats such as these are already compressed or may gain little from Gzip:

Gzip compression is most useful for text-based files such as:

Compression requires the PHP Zlib extension.

Upload security recommendations

For production upload handling:

  1. Validate the PHP upload error.
  2. Enforce a maximum file size.
  3. Detect the media type from file contents.
  4. Allow only explicitly supported media types.
  5. Generate a server-controlled storage filename.
  6. Store uploads outside the public web root when possible.
  7. Prevent script execution inside upload directories.
  8. Calculate a checksum when integrity matters.
  9. Scan untrusted files when malware detection is required.
  10. Never trust the original filename, extension or media type.

Example:

Headers

Create a header collection:

Read headers:

Set and append values:

Remove headers:

Return all values:

Flatten values into strings:

Create modified copies:

Header names and values are validated to prevent invalid names and line-break injection.

Response

Create a basic response:

Text responses

With a custom status:

HTML responses

The default content type is:

JSON responses

With a status code:

Invalid JSON values throw an InvalidArgumentException containing the original JsonException.

Redirect responses

Permanent redirect:

Temporary method-preserving redirect:

Redirect locations are validated against empty values and response-header injection.

Empty responses

Equivalent form:

Informational responses, 204 No Content and 304 Not Modified cannot contain a body.

Reading a response

Check the response category:

Transforming a response

Responses support immutable transformations.

Replace the body:

Remove a header:

The original response remains unchanged.

Sending a response

Send headers and status without the body:

Sending after PHP output has already started throws a RuntimeException.

HTTP exceptions

Create a generic HTTP exception:

Common factories are available:

Method not allowed:

Rate limiting:

Temporary service outage:

Exception headers

Some exception factories include HTTP response headers automatically.

Other examples include:

Exception context

Internal diagnostic data can be attached to an exception:

Read the context:

Exception context is intended for logs and debugging. It must not be returned directly to clients without filtering.

Converting an exception to a response

Production applications should avoid exposing internal exception messages and context for server errors.

Available classes

Headers

Request

UploadedFile

Response

HttpException

Design principles

Package boundaries

This package is responsible for:

It is not responsible for:

These responsibilities belong to other IviPHP packages.

Ecosystem

This package is part of the IviPHP ecosystem:

Contributing

Contributions should preserve the focused scope of the package.

Changes should:

Security

Please report security issues privately to the Softadastra maintainers instead of opening a public issue.

License

This project is licensed under the MIT License.

Maintainer

Created and maintained by Softadastra.


All versions of http with dependencies

PHP Build Version
Package Version
Requires php Version >=8.2
iviphp/support Version ^0.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package iviphp/http contains the following files

Loading the files please wait ...