CMS Security Settings Code

3 posts by 2 authors in: Forums > CMS Builder
Last Post: May 9, 2022   (RSS)

By depdesign - May 9, 2022

Hi all,

I need help to display content only to IPs that match an IP in the "restrictByIP" array from the CMS Security Settings.

The code below gets a site visitor IP and then checks to see if that IP is listed in the "restrictByIP" array from the CMS Security Settings.

This line, from the code below, is where I need help modifying  $safeips = array($SETTINGS['restrictByIP']);

Here is the code I have:

if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}

$safeips = array($SETTINGS['restrictByIP']);

if (in_array($ip, $safeips) !== FALSE)
{
echo "Match found display content";
} else {
echo "Match not found do not display content";
}

Dan Perez

By depdesign - May 9, 2022

That works perfectly! Thanks again for the fast response!

Dan Perez