スニッフィングされる可能性のあるhttpリファラー、プロキシの匿名化などについて説明されているすべてのことに加えて、HTTP_REFERERに依存することは優れたプログラミング標準ではありません。
代わりに、たとえば次の場合に使用します。
http://www.example.com/application/client.php
ユーザーがクリックできる場所
http://www.example.com/application/report_problem.php
作成する「...report_problem.php」レポート問題ハンドラーに「...client.php」文字列を渡すだけです。
「元の」ページのリンクを「report_problem」に渡すのは簡単で、次のように実行できます。
<?php
// pages where you will append the "problem link"
// $this_page holds an "url encoded" version of the request uri ( e.g. /application/client.php )
$this_page = rawurlencode ( $_SERVER["REQUEST_URI"] );
?>
<a href="report_problem.php?originating_page=<?=$this_page;?>">Report problem</a>
次に、「report_problem.php」コードで次のようにします。
<?php
// report_problem.php
$originating_page = ( array_key_exists ( 'originating_page', $_GET ) && ! empty ( $_GET['originating_page'] ) ? rawurldecode ( $_GET['originating_page'] ) : null;
if ( ! empty ( $originating_page ) ) {
$message = 'Error report: <p>Last site visited: ' . $originating_page . '</p>....';
mail("email@email.com", "Subject", $message);
}
else mail("email@email.com", "Subject", "Problem from unkown page");
?>