Communicating Between mod_perl and PHP (Perl Cookbook, 2nd Edition)

## 21.11. Communicating Between mod_perl and PHP

### 21.11.1. Problem

You want to build your site from both mod_perl and PHP. For example, you might want to use mod_perl for authentication and logging, while PHP generates the actual content. However, doing so means that Perl and PHP must share values; for example, so the PHP content handler knows which username successfully authenticated through mod_perl.

### 21.11.2. Solution

Use Apache notes. From Perl, you simply say:

>     $main = $r->main || $r;
>     $main->notes($KEY => $VALUE);
>     $VALUE = $main->notes($KEY);

From PHP, you say:

>     apache_note($KEY, $VALUE);
>     $VALUE = apache_note($KEY);

### 21.11.3. Discussion

A note is a string value attached to an Apache request. They're a perfect way to pass information between handlers, even when those handlers are written in different programming languages. Each request has a different set of notes, so from Perl always identify the main request and use it to communicate with PHP code.

Don't confuse the `$r->notes` method with the `$r->pnotes` method. The latter is only available to Perl modules.

### 21.11.4. See Also

Recipe 21.10

Copyright © 2003 O'Reilly & Associates. All rights reserved.