Avatar of Pete Winter
Pete WinterFlag for United Kingdom of Great Britain and Northern Ireland

asked on 

Restrict a website to one IP address

Is there a way that I could restrict a website so it is only viewable to one ip address?
PHPLinux

Avatar of undefined
Last Comment
Ray Paseur
Avatar of fosiul01
fosiul01
Flag of United Kingdom of Great Britain and Northern Ireland image

if you have iptables

iptables -A INPUT --source yy.yyy.yy.yy -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -j DROP

so it will allow ony yy.yy.yy.yy Ip to view the website

No other Ip  will be allowed
ASKER CERTIFIED SOLUTION
Avatar of MatthiasVance
MatthiasVance
Flag of Netherlands image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

In your PHP script (maybe at the top of the common code) look in the $_ENV or $_SERVER arrays.  You can find "REMOTE_ADDR"  (and maybe "REMOTE_PORT") and test these values.  Here are what mine look like right now:

REMOTE_ADDR       74.9.128.130
REMOTE_PORT       44866

But bear in mind that this is not a hardened security test - anything in the external variables can be phonied if an attacker is resourceful enough.

Best regards, ~Ray
PHP
PHP

PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.

125K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo