定制 shimabox/url-status 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

shimabox/url-status

Composer 安装命令:

composer require shimabox/url-status

包简介

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

关键字:

README 文档

README

Run Tests License Latest Stable Version Latest Unstable Version

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

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

$ vendor/bin/phpunit

License

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

统计信息

  • 总下载量: 3.99k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-08-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固