apache_note
(PHP 4, PHP 5, PHP 7, PHP 8)
apache_note — 取得或設定 apache 請求記錄
說明
apache_note(string
$note_name
, ?string $note_value
= null
): string|false
這個函式是 Apache table_get
和
table_set
的包裝。
它編輯了請求中存在的 notes 表。
這個表的目的是允許 Apache 模組進行通訊。
apache_note() 的主要用途是在同一個請求中,從一個模組傳遞資訊到另一個模組。
參數
-
note_name
-
note 名。
-
note_value
-
note 值。
返回值
如果 note_value
被省略或者為 null
,則返回記錄
note_name
的當前值。否則將記錄
note_name
的值設為
note_value
並返回記錄
note_name
的前一個值。如果未能獲取記錄,則返回 false
。
更新日誌
版本 | 說明 |
---|---|
8.0.0 |
現在 note_value 可為 null。
|
範例
示例 #1 在 PHP 與 Perl 之間傳遞資訊
<?php
apache_note('name', 'Fredrik Ekengren');
// 呼叫 perl 指令碼
virtual("/perl/some_script.pl");
$result = apache_note("resultdata");
?>
# 獲取 Apache 請求對像 my $r = Apache->request()->main(); # 獲取傳遞的數據 my $name = $r->notes('name'); # 一些處理 # 將結果返回給 PHP $r->notes('resultdata', $result);
示例 #2 在 access.log 中記錄值
<?php
apache_note('sessionID', session_id());
?>
# "%{sessionID}n" can be used in the LogFormat directive