GithubHelp home page GithubHelp logo

http_build_url's Introduction

PHP fallback function http_build_url()

For servers without pecl_http package installed.

See http://php.net/manual/en/function.http-build-url.php

Based on the original C code from pecl_http-1.7.6
http://git.php.net/?p=pecl/http/pecl_http.git;a=blob;f=php_http_url_api.h;h=940db8e61e68e1a544896a691079ad33c5b633ff;hb=b84c1c206944586e218e57a864ab9671194a10cf
http://git.php.net/?p=pecl/http/pecl_http.git;a=blob;f=http_url_api.c;h=8a70b0f2fb18b3435110b436b7f1f68023cafb15;hb=b84c1c206944586e218e57a864ab9671194a10cf

Some snippets by Sébastien Corne have been used.
https://github.com/Seebz/Snippets/blob/master/php/http_build_url.php

Version: 1.7.6
Author: Ivan Tcholakov [email protected], 2014
License: The MIT License, http://opensource.org/licenses/MIT

Usage:
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: http://iridadesign.com/starter-public-edition-4/www/non-mvc/http_build_url_test.php

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'].
See http://carlos.bueno.org/2008/06/host-header-injection.html

http_build_url's People

Contributors

ivantcholakov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

http_build_url's Issues

Array to string conversion notice for "query" components.

Hello,

I was comparing implementations of http_build_url() against a few others using your own tests and the PHPUnit tests made by @jakeasmith' for his [http_build_url](/jakeasmith/http_build_url) implementation.

His implementation failed a few of your tests and your implementation fails two tests of his:

  • testUrlQueryArrayIsIgnored
  • testPartsQueryArrayIsIgnored

I can't decipher the original C code to see if these assertions are taken into account but I thought I'd highlight this with you.

I've added these two conditions in your implementation to pass the PHPUnit test:

if (isset($url['query']) && !is_string($url['query'])) {
    $url['query'] = null;
}

if (isset($parts['query']) && !is_string($parts['query'])) {
    $parts['query'] = null;
}

What are your toughts?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.