Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shimabox/url-status
Passing the url returns the status by looking at the header information
https://github.com/shimabox/url-status
Last synced: 22 days ago
JSON representation
Passing the url returns the status by looking at the header information
- Host: GitHub
- URL: https://github.com/shimabox/url-status
- Owner: shimabox
- License: mit
- Created: 2017-08-14T08:31:15.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-07-24T13:38:58.000Z (over 2 years ago)
- Last Synced: 2024-09-06T16:47:47.309Z (4 months ago)
- Language: PHP
- Size: 14.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# url-status
[![Run Tests](https://github.com/shimabox/url-status/actions/workflows/run-tests.yml/badge.svg?branch=master)](https://github.com/shimabox/url-status/actions/workflows/run-tests.yml)
[![License](https://poser.pugx.org/shimabox/url-status/license)](https://packagist.org/packages/shimabox/url-status)
[![Latest Stable Version](https://poser.pugx.org/shimabox/url-status/v/stable)](https://packagist.org/packages/shimabox/url-status)
[![Latest Unstable Version](https://poser.pugx.org/shimabox/url-status/v/unstable)](https://packagist.org/packages/shimabox/url-status)Passing the url returns the status by looking at the header information
Inspired by [https://secure.php.net/manual/ja/function.get-headers.php#119497](https://secure.php.net/manual/ja/function.get-headers.php#119497 "PHP: get_headers - Manual")
## Installation
```
$ composer require shimabox/url-status
```## Usage
```php
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
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
```
$ vendor/bin/phpunit
```## License
The MIT License (MIT). Please see [License File](LICENSE) for more information.