Call us : 0092-323-523-6819
Mail us : admin@singlewebsolution.com
SingleWebSolution

Menu

Skip to content
  • Home
  • Web Hosting
    • Windows Web Hosting
    • Cpanel Web Hosting
    • WordPress Hosting
    • Shared Hosting
    • VPS Hosting
    • Reseller Web Hosting
  • Web Services
    • Web Designing
    • Graphic Designing
    • Responsive Web Design
    • Search Engine Optimization
    • E-Commerce Website
  • Advertising
  • Blog
  • Contact
Cart 0

    Display the Content only to the allowed IP address in PHP

    SingleWebSolution > Blog > PHP > Display the Content only to the allowed IP address in PHP
    January 16, 2019PHPControl Panel, cpanel catch all email, Dedicated Web Hosting, IP address, Linux Web Hosting, REMOTE_ADDR, Secure, SERVER, Web Hosting, Web Hosting Provider in Pakistan, Wordpress Hostingadmin

    A quick tip for only allowing access to a website for a range of IP addresses.

    This is a very simply and useful way of allowing access to only certain IP addresses maybe you have a web application that you only want to be accessed from a certain location, then this solution is perfect for that task.


    First of all create an array of IP addresses that you want to allow, make sure the last item does not have a ending comma.

    Next check if the Your IP address is in the allowed list, if its not stop the script and print a message using the die command. an you will not view your page content,

    creat IP List, if you can use just 1 IP then use this

    //allowed IP address
    $allowlist = array(
    ‘123.23.45.67’
    );

    if you want to use more IP in List the use

    //collection of allowed IP addresses
    $allowlist = array(
    ‘123.23.45.67’,
    ‘123.24.46.78’,
    ‘123.235.43.674’,
    );

    The users IP address can be accessed from a global function called $_SERVER[‘REMOTE_ADDR’].


    now this is full code, you can copy and paste just edit your IP address and add on the top of your page, header, or config

    <?php
    //collection of allowed IP addresses
    $allowlist = array(
    ‘123.23.45.67’,
    ‘123.24.46.78’,
    ‘123.235.43.674’,
    );

    localeconv($allowcity);

    //if users IP is not in allowed list kill the script
    if(!in_array($_SERVER[‘REMOTE_ADDR’],$allowlist,$allowcity))
    {
    die(‘Sorry ! you are not allow to accessed this page.’);
    }
    ?>

    Post navigation

    ← How to remove .php, .html, .htm extensions with .htaccess Top Web Hosting Companies in Pakistan →

    RSS SingleWebSolution

    • How to Improve Your Website Ranking on Google: 12 Proven SEO Strategies
    • AI-Powered Personalization: How to Make Your Website More Engaging
    • Boost Your Website Rankings with These Proven SEO Tips
    • Why Your Website Is Slow — and How to Fix It (2025 Performance Checklist)
    • 7 Reasons Your Website Looks Bad on Mobile (And How to Fix It)

    Tags

    AI AI in web design Artificial intelligence Best Hosting Company Best SEO plugin for WordPress best web hosting services Blog ChatGPT Cheap SSL Available Cheap Web Hosting cheap web hosting provider cpanel hosting Cpanel Web Web Hosting Dedicated Web Hosting eco-friendly websites Ecommerce Hosting energy-efficient websites fast website design Google Ranking How to use Yoast SEO Improve website performance Increase website engagement 2025 increase website traffic Online Shopping Store optimize website speed Personalized website experiences php Plesk Control Panel reduce website carbon footprint SEO content optimization Shared Web Hosting SingleWebSolution sustainable web design Web development Web Hosting website performance optimization Website personalization tools Wordpress Wordpress Hosting WordPress SEO plugin 2025 WordPress SEO tools wordpress web design agency Yoast SEO 2025 Yoast SEO new features Yoast SEO update 2025

    Recent Posts

    • How to Improve Your Website Ranking on Google: 12 Proven SEO Strategies
    • AI-Powered Personalization: How to Make Your Website More Engaging
    • Boost Your Website Rankings with These Proven SEO Tips
    • Why Your Website Is Slow — and How to Fix It (2025 Performance Checklist)
    • 7 Reasons Your Website Looks Bad on Mobile (And How to Fix It)

    Web Hosting

    • Web Hosting
      • Cpanel Web Hosting
      • Windows Web Hosting
      • Reseller Web Hosting
      • WordPress Hosting
      • Shared Hosting
      • VPS Hosting

    Our Web Services

    • Web Services
      • E-Commerce Website
      • Graphic Designing
      • Search Engine Optimization
      • Responsive Web Design
      • Web Designing

    Contact Us

    • Phone : 0092-323-523-6819
    • Email : admin@singlewebsolution.com
    • Website : www.singlewebsolution.com

     

    We Accept

    Payment Method, Payment Icons

    Copyright © SingleWebSolution
    imunify-bot-check
    • USD $
      US Dollar
    • PKR PKR
      Pakistani Rupees
    MENU
    • Home
    • Web Hosting
      • Windows Web Hosting
      • Cpanel Web Hosting
      • WordPress Hosting
      • Shared Hosting
      • VPS Hosting
      • Reseller Web Hosting
    • Web Services
      • Web Designing
      • Graphic Designing
      • Responsive Web Design
      • Search Engine Optimization
      • E-Commerce Website
    • Advertising
    • Blog
    • Contact