Block access based on Client IP
The opposite requires a simple exclamation mark before in_array() to change the script so that only those listed in the array will be allowed to see the site. Anything below this code will only be accessible IPs is in the array.
$valid_ips = array('123.123.123.123','32.23.13.31','123.45.678.90'); if (in_array($_SERVER['REMOTE_ADDR'],$valid_ips)) { echo "You do have permission to see this text"; die(); }
Grant access based on Client IP
This is a useful script to add at the start of any PHP file which you want hidden from a specific IP address or addresses. Anything below this first script will be hidden from anyone listed in the $valid_ips array.
$valid_ips = array('123.123.123.123','32.23.13.31','123.45.678.90'); if (!in_array($_SERVER['REMOTE_ADDR'],$valid_ips)) { echo "You do not have permission to see this text"; die(); }
Ready to elevate your website?
Whether you're launching a new site, strengthening security, or adding a new feature, I can help transform your vision into a high-performing online presence.
More Website Development posts
—
Structured data for SEO
Adding structured data to a website is one of those steps that often gets overlooked, yet it can make a real difference to how a site performs in search engines.…
—
Ensuring a smooth deployment of a PHP website application
Deploying a PHP website application requires meticulous planning, a solid understanding of the environment, and a thorough execution process. To ensure a smooth deployment, it is essential to follow best…
Continue reading "Ensuring a smooth deployment of a PHP website application"
—
Knack API Integration
Knack is a powerful low-code platform that allows you to build online databases and custom web applications. When integrating Knack with your own systems or custom front ends, you can…
—
Popular PHP frameworks
Here’s detailed look at some of the most popular PHP frameworks, each of which can help speed up development, improve code organisation, and enhance application performance. Laravel Laravel is one…