a.php
<?php
echo "<a href='http://test.im/b.php'>click me</a>";
b.php
<?php
if (isset($_SERVER['HTTP_REFERER'])) {
var_dump('referer:' . $_SERVER['HTTP_REFERER']);
}else{
var_dump("not define referer");
}
假设域名为test.im
如果直接运行:http://test.im/b.php
这会输出:
not define referer。
如果运行:http://test.im/a.php
并点击click me,跳转到 http://test.im/b.php,则会输出:
referer:http://test.im/a.php