PHP HTTP Utilities
This library provides PHP utilities functions to manage URLs. Read PHP DOC, (*1)
Install package with composer, (*3)
composer require hugsbrugs/php-http
In your PHP code, load librairy, (*4)
require_once __DIR__ . '/../vendor/autoload.php'; use Hug\Http\Http as Http;
In order to use cache mechanism, define following constants, (*5)
define('PDP_PDO_DSN', 'mysql:host=localhost;dbname=database'); define('PDP_PDO_USER', 'username'); define('PDP_PDO_PASS', 'password'); define('PDP_PDO_OPTIONS', [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
Alternatively define path to the local stored public suffix list, (*6)
define('PUBLIC_SUFFIX_LIST', realpath(__DIR__ . '/../../../cache/public_suffix_list.dat'));
This method should not be used in production since it's really slow., (*7)
Otherwise the default, not accurate, cache/public_suffix_list.dat file will be used., (*8)
Execute shell nslookup command, (*9)
Http::nslookup($url);
Check if an url is accessible (means not a 404), (*10)
Http::is_url_accessible($url);
Returns HTTP code for given URL, (*11)
Http::get_http_code($url);
Cleans an url from its query parameters, (*12)
Http::url_remove_query($url);
Cleans an url from its query parameters and path, (*13)
Http::url_remove_query_and_path($url);
Quick and dirty function to save an image from the internet, (*14)
Http::grab_image($url, $save_to);
Returns basic HTTP headers for a CURL request, (*15)
Http::get_default_headers($host);
Extracts suffix, tld, domain and subdomain from an URL, (*16)
Http::extract_all_from_url($url);
Extracts extention from an URL, (*17)
Http::extract_extension_from_url($url);
Extracts scheme (ftp, http) from an URL, (*18)
Http::extract_scheme_from_url($url);
Extracts a TLD (Top Level Domain) from an URL, (*19)
Http::extract_tld_from_url($url);
Extracts a sub domain from an URL, (*20)
Http::extract_subdomain_from_url($url);
Extracts a domain name from an URL, (*21)
Http::extract_domain_from_url($url);
Separates Headers from Body in CURL response, (*22)
Http::extract_request_headers_body($html_with_headers);
Sets a php script desired status code (usefull for API), (*23)
Http::header_status($statusCode);
Gets the address and/or http code that the provided URL redirects to. $return can be : url/code/all, (*24)
Http::get_redirect_url($url, $timeout = 5, $return = 'url');
Follows and collects all redirects, in order, for the given URL., (*25)
Http::get_all_redirects($url);
Gets the address and/or http code that the URL ultimately leads to. $return can be : url/code/all, (*26)
Http::get_final_url($url, $return = 'url');
Check a TXT record in domain zone file, (*27)
Http::check_txt_record($domain, $txt);
Waits and tests every minute if domain zone has correct IP adress and TXT record set, (*28)
Http::wait_for_zone_ok($domain, $ip, $txt_record, $wait_minutes = 15);
Tests if domain zone has correct IP adress and TXT record set, (*29)
Http::is_zone_ok($domain, $ip, $txt_record);
Get name servers of given domain, (*30)
Http::get_name_servers('maugey.fr');
Add escaped fragment to URL, (*31)
Http::add_escaped_fragment($url);
To enable CORS, put this line at top of your PHP script, (*32)
Http::cors();
Converts an URL to a filename It does not encode URL parameters (only scheme - domain - folders - file), (*33)
Http::url_2_filename($url);
https://github.com/jeremykendall/php-domain-parser https://github.com/jeremykendall/php-domain-parser/tree/5.7.0 https://publicsuffix.org/list/public_suffix_list.dat, (*34)
composer exec phpunit phpunit --configuration phpunit.xml
Hugo Maugey Webmaster | Consultant SEO | Fullstack developer, (*35)