I am planning to create a system, but I still have some questions about security. I would like to know if it makes sense to block unauthorized users from accessing the system, through the ip, using a PHP script and also firewall rules by AWS EC2, would this be good practice to prevent unauthorized users from accessing the system?
My biggest fear is to compromise the system
PHP sample code
<?php
class RemoteAddress
{
/**
* List of trusted IP addresses
*
* @var array
*/
protected $trustedIPs = array('127.0.0.1', '192.168.0.101', '192.168.0.102', '192.168.0.103');
/**
* Returns client IP address
*/
public function isDefinedIpAddress()
{
$ip = $_SERVER['REMOTE_ADDR'];
if(in_array($ip, $this->trustedIPs)){
$this->returnPage();
} else {
$this->returnErrorPage();
}
}
/**
* Redirects the user to the success page
* The user will be able to access the website
*/
private function returnPage()
{
header('Location: index.php');
exit();
}
/**
* Redirects the user to the error page
* The user will not be able to access the website
*/
private function returnErrorPage()
{
header('Location: 403.html'); //We can display an forbidden message maybe...
exit();
}
}
$object = new RemoteAddress();
$object->isDefinedIpAddress();