PHPackages                             castanet/userid - 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. [Logging &amp; Monitoring](/categories/logging)
4. /
5. castanet/userid

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

castanet/userid
===============

Emulate Nginx's HTTP Userid module

0.0.8(12y ago)43.2k2MITPHP

Since Feb 17Pushed 12y ago6 watchersCompare

[ Source](https://github.com/KitaitiMakoto/PHP-Castanet-Userid)[ Packagist](https://packagist.org/packages/castanet/userid)[ RSS](/packages/castanet-userid/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (9)Used By (0)

Castanet\_Userid
================

[](#castanet_userid)

This library emulates Apahce's [mod\_uid](http://www.lexa.ru/programs/mod-uid-eng.html) or Nginx's [User ID](http://wiki.nginx.org/HttpUseridModule) module. For the idea of User ID, visit these links.

Target Users
------------

[](#target-users)

People who

- use Apache HTTP server,
- use PHP by Apache module and
- don't use mod\_uid Apache module

Are you using Apache 1.x.x? or 2.0.x? Visit [mod\_uid page](http://www.lexa.ru/programs/mod-uid-eng.html).

Are you using Nginx? Visit [HttpUseridModule page](http://wiki.nginx.org/HttpUseridModule).

Installation
------------

[](#installation)

Add below to your composer.json:

```
"require": {
    "castanet/userid": "*"
}

```

And then execute

```
composer install

```

Usage
-----

[](#usage)

### PHP

[](#php)

```
require 'vendor/autoload.php';
$uid = new \Castanet_Userid;
$uid->enable()
    ->start();

```

You need to call `\Castanet_Userid::start()` as early as possible because it uses `setrawcookie()` function internally and `setrawcookie()` occurs error if you have output any string already.

### Apache log

[](#apache-log)

Add custome log format to `httpd.conf` like this:

```
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" \"%{uid_got}n\" \"%{uid_set}n\"" combined_cookie

```

And set `combined_cookie` as current log format, then restart Apache.

`uid_got` and `uid_set` variables are set by this library.

Settings
--------

[](#settings)

### Enabling

[](#enabling)

`Castanet_Userid` does nothing even `start()` is called unless you call `enable()`(or `setEnabled(true)`).

```
$uid = new Castanet_Userid;
$uid->start(); // do nothing
$uid->enable()->start(); // do something

```

### Name(key of cookie)

[](#namekey-of-cookie)

`name` is used as key of cookie. By default, `uid` is used:

```
uid=fwAAAVEbtF1USQfEAwMEAg==

```

You can modify it by `setConfig()` method:

```
$uid->setConfig('name', 'castanet');

```

Then key of cookie is modified:

```
castanet=fwAAAVEbtF1USQfEAwMEAg==

```

Be careful not to use the same key already used for other purpose.

### Service

[](#service)

`service` is an arbitrary integer and defaults to IP address of server PHP is processed(in practice, calculated by `ip2long()`). It appears as first eight characters on log. Let it, for instance, `127.0.0.1`, and logs noted by this library(as `uid_got` and `uid_set`) start with characters `0100007F`.

Characters themselves mean nothing but they play a role of identity. By seeing it, you may know the first server given user accessed. So you might have set the same value for multiple server load-balanced by one reverse proxy.

You can set `service` like this:

```
$uid->setConfig('service', ip2long('127.0.0.1'));

```

### Cookie attributes

[](#cookie-attributes)

Cookie attributes(`domain`, `path` and `expires`) are able to be set by `setConfig()` method:

```
$uid->setConfig('domain', 'www.example.net')
    ->setConfig('path', '/sandbox');

```

### Setting at a time

[](#setting-at-a-time)

Using `setConfigs()` method, you can set properties above at a time:

```
$uid->setConfigs(array(
    'name'    => 'castanet',
    'service' => ip2long('127.0.0.1'),
    'domain'  => 'www.example.net',
    'path'    => '/sandbox'
));

```

### Merged uid

[](#merged-uid)

Now Castanet Userid notes a note `uid` in addition to `uid_set` and `uid_got`. It is the value of either exists `uid_set` or `uid_set` and it doesn't have key name(`uid=`).

PHP 4
-----

[](#php-4)

For PHP 4, Use Castanet\_Userid4.

Contributors
------------

[](#contributors)

- [Wackham](https://github.com/yuma3009)

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity58

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 ~26 days

Total

7

Last Release

4682d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/202e35ba39b0c1a7e657c8da382513f39b124e6832123c8b474931eba337792b?d=identicon)[KitaitiMakoto](/maintainers/KitaitiMakoto)

---

Top Contributors

[![KitaitiMakoto](https://avatars.githubusercontent.com/u/386512?v=4)](https://github.com/KitaitiMakoto "KitaitiMakoto (50 commits)")

---

Tags

loggingcookieapache

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/castanet-userid/health.svg)

```
[![Health](https://phpackages.com/badges/castanet-userid/health.svg)](https://phpackages.com/packages/castanet-userid)
```

###  Alternatives

[monolog/monolog

Sends your logs to files, sockets, inboxes, databases and various web services

21.4k964.9M7.0k](/packages/monolog-monolog)[symfony/monolog-bundle

Symfony MonologBundle

2.9k249.1M1.6k](/packages/symfony-monolog-bundle)[itsgoingd/clockwork

php dev tools in your browser

5.9k27.6M94](/packages/itsgoingd-clockwork)[sentry/sentry

PHP SDK for Sentry (http://sentry.io)

1.9k227.1M273](/packages/sentry-sentry)[sentry/sentry-laravel

Laravel SDK for Sentry (https://sentry.io)

1.3k114.3M154](/packages/sentry-sentry-laravel)[sentry/sentry-symfony

Symfony integration for Sentry (http://getsentry.com)

73661.4M66](/packages/sentry-sentry-symfony)

PHPackages © 2026

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