PHPackages                             old-smoke-gun/php-jwt - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. old-smoke-gun/php-jwt

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

old-smoke-gun/php-jwt
=====================

jwt for php

1.0.2(6y ago)08.5k1Apache License 2.0PHPPHP &gt;=7.0

Since Dec 10Pushed 6y agoCompare

[ Source](https://github.com/OldSmokeGun/php-jwt)[ Packagist](https://packagist.org/packages/old-smoke-gun/php-jwt)[ RSS](/packages/old-smoke-gun-php-jwt/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (4)Used By (1)

### 适用于 `PHP` 的 `JWT` 扩展包

[](#适用于-php-的-jwt-扩展包)

### 使用：

[](#使用)

- 注意：密钥必须设置
- 生成 `token`

```
$jwt = new \oldSmokeGun\Jwt\Jwt();

$token = $jwt->setSecret('secret') // 设置密钥
    ->setAlg('md5') // 设置加密方式
    ->setIss('张三') // 设置签发者
    ->setSub('测试') // 设置主题
    ->setAud('王五') // 设置接收者
    ->setExp(time() + 7200) // 设置过期时间
    ->setNbf(time()) // 设置 token 生效时间
    ->setExtraData([ // 设置额外数据
        'name' => '李四',
        'age'  => 18
    ])
    ->build();
```

- 校验

```
$jwt = new \oldSmokeGun\Jwt\Jwt();

$result = $jwt->setSecret('secret')
              ->validate('eyJ0eXBlIjoiSldUIiwiYWxnIjoibWQ1In0=.eyJpc3MiOiLlvKDkuIkiLCJzdWIiOiLmtYvor5UiLCJhdWQiOiLnjovkupQiLCJleHAiOjE1NzU5NjY1MTksIm5iZiI6MTU3NTk1OTMxOSwiaWF0IjoxNTc1OTU5MzE5LCJqdGkiOiI1MTBmYmI0ZmIyMTNmNzA1MmFmMjk3ZDFiNjEwZDU4MiIsInB1YiI
          6W10sInByaSI6W119.73ac0c3d5f7d8a8f85c2d91418976b83');

switch ( $result )
{
    case 0 :
        echo 'token 有效';
        break;
    case 1 :
        echo '签名验证错误';
        break;
    case 2 :
        echo 'token 不可用';
        break;
    case 3 :
        echo 'token 已过期';
        break;
}
```

- `token` 解析

```
$jwt = new \oldSmokeGun\Jwt\Jwt();

$data = $jwt->parse('eyJ0eXBlIjoiSldUIiwiYWxnIjoibWQ1In0=.eyJpc3MiOiLlvKDkuIkiLCJzdWIiOiLmtYvor5UiLCJhdWQiOiLnjovkupQiLCJleHAiOjE1NzU5NjY1MTksIm5iZiI6MTU3NTk1OTMxOSwiaWF0IjoxNTc1OTU5MzE5LCJqdGkiOiI1MTBmYmI0ZmIyMTNmNzA1MmFmMjk3ZDFiNjEwZDU4MiIsInB1YiI
        6W10sInByaSI6W119.73ac0c3d5f7d8a8f85c2d91418976b83');
```

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~53 days

Total

3

Last Release

2289d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/30717069?v=4)[OldSmokeGun](/maintainers/OldSmokeGun)[@OldSmokeGun](https://github.com/OldSmokeGun)

---

Top Contributors

[![OldSmokeGun](https://avatars.githubusercontent.com/u/30717069?v=4)](https://github.com/OldSmokeGun "OldSmokeGun (8 commits)")

---

Tags

phpjwt

### Embed Badge

![Health badge](/badges/old-smoke-gun-php-jwt/health.svg)

```
[![Health](https://phpackages.com/badges/old-smoke-gun-php-jwt/health.svg)](https://phpackages.com/packages/old-smoke-gun-php-jwt)
```

###  Alternatives

[griffinledingham/php-apple-signin

A simple library to decode and parse Apple Sign In client tokens.

2012.0M1](/packages/griffinledingham-php-apple-signin)[hyperf-ext/jwt

The Hyperf JWT package.

53138.7k2](/packages/hyperf-ext-jwt)[maicol07/flarum-ext-sso

SSO for Flarum

468.7k](/packages/maicol07-flarum-ext-sso)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
