Tại functions.php, thêm đoạn mã sau.
$ref = $_SERVER['HTTP_REFERER'];
$SE = array('/search?', 'images.google.', 'search.', '/search/');
foreach ($SE as $source) {
if (strpos($ref, $source) !== false) {
setcookie("sevisitor", 1, time() + 3600, "/", ".inithtml.com");
$sevisitor = true;
}
}
function user_from_searchengine(){
global $sevisitor;
if ($sevisitor == true || $_COOKIE["sevisitor"] == 1) {
return true;
}
return false;
}
Để sử dụng, các bạn dùng đoạn mã sau ở chỗ cần chèn quảng cáo.
<?php
if (function_exists('user_from_searchengine')) {
if (user_from_searchengine()) {
?>
<!-- Code quảng cáo -->
<?php } } ?>
Chúc các bạn thành công!
Bình luận