I'm not a PHP developer at all, this is a script provided by a theme to restrict access to whitelisted IP addresses. I'm hoping to amend it so that it if a whitelisted IP exists, it loads WordPress (as it does now), else if the IP does not exist in the array, it checks for a cookie. If the cookie exists (passedSecurityTT) show WordPress and lastly, if both do not exist - redirect to /login.php.
<?php
$whitelist = array('111.222.333.444', '111.222.333.445');
if (in_array($_SERVER['REMOTE_ADDR'], $whitelist)) {
define('WP_USE_THEMES', true);
/** Loads the WordPress Environment and Template */
require('./wp-blog-header.php');
} else {
//Action for all other IP Addresses
echo 'You are not authorized here.';
echo "<br />IP Address: ".$_SERVER['REMOTE_ADDR'];
exit;
}
elseif (!isset($_COOKIE['passedSecurityTT'])) {
define('WP_USE_THEMES', true);
/** Loads the WordPress Environment and Template */
require('./wp-blog-header.php');
} else {
//Action for all other IP Addresses
echo 'You are not authorized here.';
echo "<br />IP Address: ".$_SERVER['REMOTE_ADDR'];
exit;
}
else {
header('Location: /login.php');
}
But I'm getting an error on Line 16: Parse error: syntax error, unexpected T_ELSEIF in /home/public_html/index.php on line 16
Can anyone help? Also thinking I should wrap this in a function somehow, as it's repeated...
define('WP_USE_THEMES', true);
/** Loads the WordPress Environment and Template */
require('./wp-blog-header.php');
} else {
//Action for all other IP Addresses
echo 'You are not authorized here.';
echo "<br />IP Address: ".$_SERVER['REMOTE_ADDR'];
exit;
}