PHP fallback function http_build_url()
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

PHP fallback function http_build_url()

For servers without pecl_http package installed.


Based on the original C code from pecl_http-1.7.6;a=blob;f=php_http_url_api.h;h=940db8e61e68e1a544896a691079ad33c5b633ff;hb=b84c1c206944586e218e57a864ab9671194a10cf;a=blob;f=http_url_api.c;h=8a70b0f2fb18b3435110b436b7f1f68023cafb15;hb=b84c1c206944586e218e57a864ab9671194a10cf

Some snippets by Sébastien Corne have been used.

Version: 1.7.6
Author: Ivan Tcholakov, 2014
License: The MIT License,

Place this file on a suitable directory of your PHP system.
Inside a common bootstrap file within your system insert the following piece of code:

if (!function_exists('http_build_str') || !function_exists('http_build_url')) {
    require dirname(__FILE__).'/write/your/relative/path/here/http_build_url.php';

After that, the functions http_build_url() and http_build_str() would be callable.
A quick test:

echo http_build_url();

For testing this fallback implementation, place the file http_build_url_test.php on the web-server too, and open it with a browser. Don't forget to remove it when it is no longer needed.

Live test demo:

An important note: Don't use host autodetection (or more generally base url autodetection) implemented by this function, it relies first on $_SERVER['HTTP_HOST'].