2017 © Pedro Peláez
 

library url-status

Passing the url returns the status by looking at the header information

image

shimabox/url-status

Passing the url returns the status by looking at the header information

  • Tuesday, August 15, 2017
  • by shimabox
  • Repository
  • 1 Watchers
  • 0 Stars
  • 1,223 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 8 % Grown

The README.md

url-status

Run Tests License Latest Stable Version Latest Unstable Version, (*1)

Passing the url returns the status by looking at the header information, (*2)

Inspired by https://secure.php.net/manual/ja/function.get-headers.php#119497, (*3)

Installation

$ composer require shimabox/url-status

Usage

<?php
require_once 'vendor/autoload.php';

$ret = \SMB\UrlStatus::get($url);

$ret->targetUrl();      // string 対象のURL
$ret->reachedUrl();     // string 最後に到達したURL
$ret->isValidUrl();     // bool   有効なURLか
$ret->redirectedUrls(); // array  リダイレクトがあった際のURL
$ret->redirectedCode(); // array  リダイレクト時のHTTPステータスコード
$ret->code();           // int    最終的なHTTPステータスコード

// is{数値3桁}() でマジックメソッドが呼ばれます
$ret->is200();          // bool   HTTPステータスコードが200かどうか
$ret->is401();          // bool   HTTPステータスコードが401かどうか
$ret->is403();          // bool   HTTPステータスコードが403かどうか
$ret->is404();          // bool   HTTPステータスコードが404かどうか
$ret->is405();          // bool   HTTPステータスコードが405かどうか
$ret->is500();          // bool   HTTPステータスコードが500かどうか
$ret->is503();          // bool   HTTPステータスコードが503かどうか
.
.
$ret->isxxx();          // /\Ais(\d{3})\z/ will call the magic method

Example

<?php
require_once 'vendor/autoload.php';

$ret = \SMB\UrlStatus::get('https://google.com/webhp?gl=us&hl=en&gws_rd=cr');

$ret->targetUrl();      // => 'https://google.com/webhp?gl=us&hl=en&gws_rd=cr'
$ret->reachedUrl();     // => 'https://www.google.com/webhp?gl=us&hl=en&gws_rd=cr'
$ret->isValidUrl();     // => true
$ret->redirectedUrls(); // => ['https://www.google.com/webhp?gl=us&hl=en&gws_rd=cr']
$ret->redirectedCode(); // => [301]
$ret->code();           // => 200
$ret->is200();          // => true

// for the POST method
$data = http_build_query(['foo' => 'bar', 'hoge' => 'piyo']);
$header = [
    'Content-Type: application/x-www-form-urlencoded',
    'Content-Length: ' . strlen($data)
];
$options = [
    'http' => [
        'method'  => 'POST',
        'header'  => implode("\r\n", $header),
        'content' => $data
    ]
];

$ret = \SMB\UrlStatus::get('http://localhost/post.php', $options);

Testing

$ composer test

or, (*4)

$ vendor/bin/phpunit

License

The MIT License (MIT). Please see License File for more information., (*5)

The Versions

15/08 2017

dev-master

9999999-dev https://github.com/shimabox/url-status

Passing the url returns the status by looking at the header information

  Sources   Download

MIT

The Requires

  • php ^5.4|^7.0

 

The Development Requires

by Avatar shimabox

http header

15/08 2017

v1.0.0

1.0.0.0 https://github.com/shimabox/url-status

Passing the url returns the status by looking at the header information

  Sources   Download

MIT

The Requires

  • php ^5.4|^7.0

 

The Development Requires

by Avatar shimabox

http header