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

Menu

Skip to content
  • Home
  • Web Hosting
    • Windows Web Hosting
    • Linux 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

    • Uncaught ReflectionException: Method get_site_editor_type does not exist
    • How do I open social media links in a new tab – Shopify
    • How to Get Elementor Pro For Free Latest Version
    • How cPanel Helps The Web Host Save Time and Money
    • How To Convert Website into Professional Android App Using Android Studio

    Tags

    affordable web design Best Hosting Company Best Hosting Company in 2020 Best Hosting for Blog best hosting provider best web hosting services Blog Blogger Change Default index page cPanel Cheap Linux Web Hosting Cheap SSL Available Cheap Web Hosting Cheap Web Hosting Plan Cheap Web Hosting Plan for blog cheap web hosting provider cpanel hosting cpanel manual cpanel setting Cpanel Web Web Hosting Dedicated Web Hosting Ecommerce Hosting Elementor pro version file manager get pro version for free graphic design business graphic designer agency hosting in pakistan increase timeout in cpanel Links in new tab linux server configuration Linux web Hosting with cpanel Online Shopping Store php Plesk Control Panel Shared Web Hosting Shopify Customistion shopify help SingleWebSolution Social Meda Links Social media links in shopify Web development Web Hosting Wordpress Wordpress Hosting wordpress web design agency

    Testimonials

    wordpress-e-commerce website

    “Great person to work with. Understood what I need and worked diligently to get it done. Went above and beyond to meet my requirements sometimes on the spot.”

    November 8, 2019

    WordPress website

    “Great person to work with. Went above and beyond to help me to developed and fix an issue on my WordPress site. Very diligent and kept working until the issue was resolved. Would definitely re-hire.”

    Upwork November 8, 2019

    Developer needed for creating a responsive website – Information Technology

    “Great Web Developer and Communication. Would rehire in future for more work.”

    Upwork November 8, 2019

    Create one page website and blog site

    “Great website builder and very good to work with. Always proactive an accommodative. Will work with again for sure.”

    Upwork April 28, 2020

    Website design

    ” Very good in communication and enterprise Mudassar helped realise my dental website by working hard and helping me a lot with sourcing assets making revisions, searching for best solutions possible. Highly recommended.”

    Upwork May 2, 2020

    Create Dance website

    “Great communication and dedication. Will hire again.”

    Upwork July 5, 2020

    Best Web Hosting Provider

    “Professionalism, Quality, Responsiveness, Value Very positive professional behavior. Excellent services. Proper Feedback and the best in the town.”

    Google July 24, 2020

    << Prev
    Next >>

    Recent Posts

    • Uncaught ReflectionException: Method get_site_editor_type does not exist
    • How do I open social media links in a new tab – Shopify
    • How to Get Elementor Pro For Free Latest Version
    • How cPanel Helps The Web Host Save Time and Money
    • How To Convert Website into Professional Android App Using Android Studio

    Web Hosting

    • Web Hosting
      • Linux 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

    Find Us

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

     

    We Accept

    Copyright © SingleWebSolution
    This website uses cookies to improve your experience. Accept Read More
    Privacy & Cookies Policy

    Privacy Overview

    This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
    Necessary
    Always Enabled
    Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
    Non-necessary
    Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
    SAVE & ACCEPT
    • USD $
      US Dollar
    • PKR PKR
      Pakistani Rupees
    MENU
    • Home
    • Web Hosting
      • Windows Web Hosting
      • Linux 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