There are two pieces to this code: 1) Interpreting the list of allowed IPs from a textarea, delimited by newline character, and 2) Checking if a given user’s IP is in the allowed list of IPs.
Part 1) Parse list of IPs delimited by newline character, and trim whitespace:
$_POST['allowed_ips'] = " 67.6.134.102
97.118.69.236 ";
$ips = array_map('trim', explode("\n", $_POST['allowed_ips']));
var_dump($ips); //This should match your Array() output from above
Part 2) Check list of allowed IPs against the user’s current IP:
var_dump(in_array($_SERVER['REMOTE_ADDR'], $ips));
in_array() allows you to take a string and check if it exists as a value in an array. Since you have a list of all IPs you want to allow, you just need to check if the user’s current IP ($_SERVER['REMOTE_ADDR']) is in the array of allowed IPs.
Related Posts:
- Minecraft Server closes immediately after running?
- WAMP vs XAMPP pros/cons – for running a local testing server [closed]
- WordPress local development environment [closed]
- Can you host WordPress using Amazon Web Services such as EC2, RDS, EBS etc?
- Character encoding issue after changing servers
- WordPress .htaccess subdirectory problem
- Implement ssl to a WP docker container [closed]
- Apache/Linux configuration changes to make automatic upgrade more straightforward
- Testing local server with MAMP/wordpress on mobile device? [closed]
- Arabic Characters in URL returns 404 Error
- Connect to server with SFTP instead of FTP/FTPS within WordPress Backup
- WordPress hangs when I publish or update a post [closed]
- Force Cron to run only on one server
- Gutenberg: unable to save attributes with ServerRender
- WordPress incorrectly redirects to local IP address?
- Handling the response sent from a ruby on rails application in wordpress
- How might I setup a development server (local) and a test/production server (remote)
- Why does WordPress get posts from MySQL from a virtual hostname but not the direct hostname?
- Can you have multiple wordpress sites under the same domain?
- Can’t delete unwanted favicon
- How to Better Control WordPress Cron Jobs?
- Changing the server path
- Editing post and page responding 503 Service Unavailable
- Two live WP websites – how to sync?
- what are the chmod rights recommended to give for every folders of wordpress projects
- WordPress installation site folder move to the final site destination
- WordPress hosting optimized servers – Is this just a sales gimmick? [closed]
- External cron job firing too many times
- Does WP read itself?
- SSH Upgrade Problem
- Archived Server for Reference – Unable to Navigate Passed Homepage
- dev site running on subdomain is redirecting to the main domain
- copy wordpress site files on new server
- Lamp stack not supporting phpmyadmin? [closed]
- HTTP Error on media upload, only httpd restart helps
- Moving wordpress to an unknown outlet
- White screen on front page only
- Log Author Actions
- WordPress hosting moved from windows server to linux server
- WordPress backup(on another server)leading to old server addy and WP
- cURL error for cron
- WordPress sub-directory on other server running on nginx?
- Server specification [closed]
- how to move another machine or server without dealing with IP
- How to change settings so I can upload images in WordPress posts?
- WordPress FTP via admin panel slow
- Scripts external to WordPress cause 404 errors
- WordPress PHP version/info not being picked from cPanel PHP Version values
- Changing domain name causes some strange problem in my browser
- Sequence of finding a website when they are running WordPress
- i have a problem with my domain getting rederected to another one
- How to optimize wp_delete_post() function, or why it is so slow
- Adding a “code checker” for my e-learning wordpress site
- localhost/wordpress(or other application), how does it work?
- WordPress vps memory allocation
- Getting past the Synology default web site when creating a web server
- Internal Server Error after restoring MySQL databases
- Apache using full RAM problem
- Best WordPress Cloud Hosting Provider that allows installation of ffmpeg 4.0
- Server (VPS) is going down when editing a bigger wordpress article! (?)
- URL problem in my site
- Setting up WordPress client and server
- Migrating WordPress from Windows Server 2008 R2 (IIS v7.5) to CentOS
- Formatting wordpress debug messages
- PressPi (WordPress) Broken Layout
- Multi-server environment is causing problems in WordPress
- Best practices for configuring a server?
- Does WordPress perform better with curl installed?
- WordPress or plugin need tomcat?
- Trouble getting wordpress working after moving servers
- Apache extensions for WordPress’ working without troubles
- WordPress keeps crashing my server
- WordPress not working locally
- Would Amazon AWS Services be a good alternative to my current hosting provider?
- WordPress site causing lots of server IO
- What level of permissions should the plugins folder be set to?
- Download a zip folder of selected files
- Problems with ‘require (./xxx)’ on IIS7.5
- Moving a WordPress website from one server to another
- Where can I find web hosting reviews? [closed]
- Check WordPress size on disk
- Will denying all ip address except my own create a problem?
- Reduce initial server response time wordpress
- existing server and domain with new webpage
- Server setup sanity check on theme changes
- What is a Context Free Grammar?
- Grep and Python
- Using Bash regex match (=~) where regex includes quotes (” characters)
- What is the grep equivalent in Python?
- Can a URL contain a semicolon and still be valid?
- Regex Last occurrence?
- How to count string occurrence in string?
- Using strip() to clean up a string
- Error establishing a database connection After Copy localhost wordpress site (with site url directly to hosting server’s url before copy)
- WordPress Site Running Extremely Slow on Dedicated Server
- Can you run WordPress on a MarketLive/Java EE server?
- Correct user session/cookie handling with external site connection in wordpress
- Regex For Extracting First 4 letters of search term
- Is there a way to get wp_editor (tinymce) content?
- Unexpected Login Redirect in Localhost WordPress Sites