Last active
December 10, 2015 02:39
-
-
Save QB/4369576 to your computer and use it in GitHub Desktop.
アクセスログもどきをjson風に記録。好きな環境変数を手軽に記録できます。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// PHPでuser_agent.datにアクセスログもどきをjson風に記録する。こんなもの実用化したら、読み込みが遅くなってお話にならないので、要注意。 | |
// $item に好きなものを入れれば、好きな環境変数を記録可能。put($file_name)でログの吐き出しが可能。 | |
$item = array( | |
"REQUEST_URI", | |
"HTTP_USER_AGENT", | |
"REMOTE_ADDR" | |
); | |
$file_name = "user_agent.dat"; | |
function q($s){ $q = "\""; return $q.$_SERVER[$s].$q; } | |
$data = "["; | |
foreach ($item as $i) $data.= q($i).","; | |
$data .= "],"; | |
file_put_contents($file_name, $data, FILE_APPEND); //なければファイルは自動で作られる | |
function put($s){ | |
echo file_get_contents($s); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment