apache_note() does not work on requests to a symlink, only on actual files. Eg. if index.php is symlinked to login.php, then any apache_note() in login.php will not be available to other apache modules such as logging.
apache_note
(PHP 4, PHP 5)
apache_note — Setzt und liest Apache Request Notes
Beschreibung
$note_name
[, string $note_value = ""
] )Diese Funktion ist ein Wrapper für das table_get und table_set von Apache. Sie editiert die Notestabelle, die während eines Requests existiert. Der Sinn dieser Tabelle ist es, die Kommunikation zwischen Apachemodulen zu ermöglichen.
Der primäre Anwendungsfall für apache_note() ist die Übergabe von Informationen von einem Modul an ein anderes während der Abarbeitung eines bestimmten Requests.
Parameter-Liste
-
note_name -
Der Name der Note.
-
note_value -
Der Wert der Note.
Rückgabewerte
Wenn die Funktion mit einem Argument aufgerufen wird, gibt sie den aktuellen
Wert der Note note_name zurück. Wird sie mit zwei
Argumenten aufgerufen, setzt sie den Wert der Note note_name
auf note_value und gibt den vorigen Wert der Note
note_name zurück. Wenn die Note nicht angesprochen werden
kann, wird FALSE zurückgegeben.
Beispiele
Beispiel #1 Übergeben von Informationen zwischen PHP und Perl
<?php
apache_note('name', 'Fredrik Ekengren');
// Perl-Skript aufrufen
virtual("/perl/some_script.pl");
$result = apache_note("resultdata");
?>
# Hole das Apache Request Objekt
my $r = Apache->request()->main();
# Hole die übergebenen Daten
my $name = $r->notes('name');
# beliebige Verarbeitung
# Reiche das Ergebnis an PHP zurück
$r->notes('resultdata', $result);
Beispiel #2 Werte in access.log loggen
<?php
apache_note('sessionID', session_id());
?>
# "%{sessionID}n" kann in der LogFormat-Direktive verwendet werden
apache_note
16-Oct-2001 10:52
06-Sep-2001 09:25
Used this with mod_layout... very handy. :) Used my PHP code in my header to check session variables and validate the session. If the session is not valid, I use apache_note to tell mod_layout not to display the content page or the footer, just the error page I generate in the header page.
Note: successive calls to apache_note with the same KEY overwrite the VALUE. Ie:
apache_note("LAYOUT","originoff");
apache_note("LAYOUT","footeroff");
Will only send the last note. You need to do something like:
apache_note("LAYOUT","originoff");
apache_note("LAYOUT-2","footeroff");
To get both variables through. How you retrieve this is obviously up to the module receiving notes, of course...
--Nathan
24-Jul-2001 01:45
In a project I was involved in, we needed to pass data from mod_php4 to mod_perl. We used apache_note() to do the work for us.
It took a little while to figure it out, but here's some sample code that could help anyone with the same problem.
From PHP file:
<?
apache_note("name", $HTTP_COOKIE_VARS["User"]);
// Put all post variables into apache notes
while (list($key,$value) = each($HTTP_POST_VARS))
apache_note($key, $value);
// Call perl script
virtual("/perl/some_script.pl");
$result = apache_note("resultdata");
?>
From Perl file:
# Get Apache request object
my $r = Apache->request()->main();
# Get passed data
my $name = $r->notes('name');
my $more_data = $r->notes('more_data');
# some processing
# Pass result back to PHP
$r->notes('resultdata', $result);
// Fredrik
12-Sep-1999 12:48
This function is a wrapper for Apache's table_get and table_set. It
edits the table of notes that exists during a request. The table's
purpose is to allow Apache modules to communicate. Here are some
further details I found in the mailing list archives:
<P>
Rasmus wrote:
<P>
The main use for apache_note() is to pass information
from one module to another within the same request. I haven`t seen an
actual implementation that uses this yet, but it is quite possible for
someone to write a module which performs some sort of action at one of the
other stages of the request and stores some information in the Apache note
table which will then be available to PHP when the request reaches the
content-handling stage. Or, one could have a logging module that reads
something from the Apache Note table set by PHP.
<P>
David Sklar wrote:
<P>You can use it to facilitate communication between modules that act on the
request at different stages. I use it to record userids in logfiles. In
some PHP that gets auto_prepend-ed, I do a
<P>
apache_note(`sessionID`,$sessionID);
<P>
(where $sessionID has been slurped out of a cookie and processed)
<P>
and then, in my httpd.conf, part of my LogFormat is
<P>
"%{sessionID}n"
<P>
so that sessionID gets written to the logfile.
<P>
If you have other modules that process the request before or after PHP
does (authentication, fixups, whatever..) you can have them talk to PHP or
PHP talk to them through the notes table.