Reputation: 21
I build a dashboard using PHP & MySql, where my company employees can log in, log out, request leaves, add work reports & maintain their attendance. everything was working fine, but my manager wants that dashboard to open only in our office network. Since it's a simple task, I added the below code to the login page.
<?php
$ip = $_SERVER['REMOTE_ADDR'];
if($ip == "xxx.xxx.xxx.xxx")
{
}
else
{
header("Location: error.php");
}
?>
On the error.php page, I added an error message "You are not allowed to access this page".
The IP address I am using is from Google (IPV4). This was working fine but recently I realized the internet IP address changes often. Now the condition is not working. So anyone can help me with which IP address I need to use in the conditions or what will be the solution for this.
Upvotes: 0
Views: 1159
Reputation: 21
The issue has been resolved. If anyone looking for the answer,
The simplest solution I found on internet is allowing the entire subnet.
.htaccess code:
Order Deny,Allow
Deny from all
Allow from 111.111
Since the IPV4 is varying, I observed 1st 6 digits are static & only last 6 digits were varying.
So I removed PHP functions & using the above code in the htaccess I allowed the entire subnet (through 1st 6 digits)
Upvotes: 0
Reputation: 17413
There are two ways:
Your approach is similar to the first one, only that you're trying to reimplement what your webserver already offers out of the box.
Upvotes: 1
Reputation: 31
You mean the IP of your company is not static and changes regularily ?
If so, you could create a script running on a computer in your company that would update the allowed IP on the server.
Upvotes: 0