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

  • Home
  • SEARCH
  • 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 5967733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:59:12+00:00 2026-05-22T19:59:12+00:00

I am building an admin panel. and I want to block certain IP ranges.

  • 0

I am building an admin panel. and I want to block certain IP ranges. I’m testing this on my localhost wamp server but ir doesn’t seem to redirect me.

<?php
   if($_SERVER['REMOTE_ADDR'] == '127.0.0..*') 
      header("Location: http://google.com");
   else
      echo "Hai";
?>

Any input is appreciated.

  • 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-05-22T19:59:13+00:00Added an answer on May 22, 2026 at 7:59 pm

    Is sufficient to use string comparison

    if (strncmp('127.0.0.', $_SERVER['REMOTE_ADDR'], 8) === 0)
      header("Location: http://google.com");
    else
      echo "Hai";
    

    Update: Taken from the comments of inits answer

    Suppose i want to block any IP coming from this range: 192.168.0.1-255. What would be the best solution for it ? Thanks.

    Then just make the same string comparison against this block

    if (strncmp('192.168.0.', $_SERVER['REMOTE_ADDR'], 10) === 0)
      header("Location: http://google.com");
    else
      echo "Hai";
    

    If you want to test the remote address against both blocks at once, you will probably put them together into one expression. This time we need a different approach

    if (in_array(substr($_SERVER['REMOTE_ADDR'], 0, strrpos($_SERVER['REMOTE_ADDR'], '.')), array('127.0.0', '192.168.0'))) {
      header("Location: http://google.com");
    else
      echo "Hai";
    

    The substr()-part takes the IP until the last .. We can just try to find this string in a set (-> array) of IP-prefixes.

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

Sidebar

Related Questions

I'm building a (CakePHP) website with an admin section that allows rich text editing
I'm currently building a job-board website with CodeIgniter 2.0 that is very user content
I am building a CMS using Ruby on Rails to teach myself the framework.
Iam building a custom rating bar. With help of kozyr's article i have created
When building a multi-framework package for Nuget you need to divide up the library
When building an iPhone app that uses the Core Plot framework, I am seeing
My company uses one build machine (a Mac Mini) as a CI node to
I'm trying to use my fixtures in a UnitTest. AddFavoritesTestCase(unittest.TestCase): fixtures = ['/Users/Bryan/work/osqa/fixtures/fixture_questions.json'] def
being a Java/Linux advocate, and having programmed my first Android app a while ago,

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.