Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8207841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:07:53+00:00 2026-06-07T09:07:53+00:00

I have a script where payment processors come with payment confirmations. To make the

  • 0

I have a script where payment processors come with payment confirmations.
To make the page secure, as it can access order information and other user related stuff, I had to limit the acces by ip(/24) as it follows:

$ipAllowed = array(
'192.192.192',
'172.172.172'
);
$ipAllowed = str_replace(".", "\.", implode("|", $ipAllowed));

if(!preg_match("/^($ipAllowed)\.[0-9]{1,3}$/", $_SERVER['REMOTE_ADDR'])){
     header('HTTP/1.0 403 Forbidden');
     die('You are not allowed to access this file.');
}

*the ip’s are just as an example

Before i used:

if(!in_array(@$_SERVER['REMOTE_ADDR'], array('ips here'))); //only works with full ip

The !in_array was much neater then the one I use now, but i need something that works with /24 ips, or even with both!

Do you know something that works better/faster, is reliable and much neater?

@rap-2-h As you stated this is the neater version that works with full ip, /24 or even /16

$ipAllowed = array( '192.168.1.153' '172.172.172'); 
$allowed = false; 

foreach($ipAllowed as $ip): 
    if(strpos($_SERVER['REMOTE_ADDR'], $ip) === 0) $allowed = true; 
endforeach; 

if (!$allowed) { 
    header('HTTP/1.0 403 Forbidden'); 
    die('You are not allowed to access this file.'); 
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T09:07:54+00:00Added an answer on June 7, 2026 at 9:07 am

    You can try something like this :

    $ipAllowed = array('192.192.192', '172.172.172');
    
    $allowed = false;
    foreach($ipAllowed as $ip) {
         if (strpos($_SERVER['REMOTE_ADDR'], $ip) !== false) {
             $allowed = true;
         }
    }
    if (!$allowed) {
        header('HTTP/1.0 403 Forbidden');
        die('You are not allowed to access this file.');     
    }
    

    So you can have only ip fragment in your $ipAllowed array.
    It’s not very elegant but it should work…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have script which allows to display Bing search results. I can call for
I have a Python CGI handling a payment transaction. When the user submits the
I have a payment button on a page that submits info to a payment
I'm currently integrating a payment system into my website. I have a response script
I have script that reads remote file content and writes it to local server.
i have script for insert multiple rows : protected static final String INSERT_NAME_LIST1 =
I have script file where a command is stored in a variable First i
I have script like this : fullscript.sh if [ ! -f /opt/laks/linux-2.6.33.2.tar.bz2 ] then
I need to have script.sh , that would create files f1.txt and f2.txt with
i have a script which is for virtual keyboard, i am facing some problem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.