Find Article
Monday, May 23, 2011
Php Code: Check referer
Simply put the code in your sites functions.php and call it in page_head.php!
check_referer()
check_referer("./difname")
<!-- This Script is from www.hawkee.com, found at www.phpfreecode.com-->function is_ipv4($s){ $n = "([0-9]|1?\d\d|2[0-4]\d|25[0-5])"; return preg_match("#^{$n}\.{$n}\.{$n}\.{$n}$#", $s);}function check_referer($db_referer = "./referer.txt"){ if ( !preg_match("#http://(.*?)/(.*)#", $_SERVER["HTTP_REFERER"], $m) ) { return false; } if ( !is_ipv4($m[1]) && is_numeric(strpos($m[1], '.')) && substr_count($m[1], '.') > 1 ) { $m[1] = strrev($m[1]); $m[1] = substr($m[1], 0, strpos($m[1], '.', strpos($m[1], '.') + 1)); $m[1] = strrev($m[1]); } if ( $m[1] == $_SERVER["HTTP_HOST"] ) { return false; } if ( file_exists($db_referer) ) { $referer = unserialize(file_get_contents($db_referer)); } else { $referer = array(); } if ( !isset($referer[$m[1]]) ) { $referer[$m[1]] = 0; } $referer[$m[1]]++; file_put_contents($db_referer, serialize($referer)); return true;}<br><font face="Tahoma"><a target="_blank" href="http://www.phpfreecode.com/"><span style="font-size: 8pt; text-decoration: none">PHP Free Code</span></a></font>
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment